Skip to content

Commit 7695112

Browse files
fabpotRobin Chalas
authored andcommitted
feature symfony#22317 [Console] Make SymfonyQuestionHelper::ask optional by default (ro0NL)
This PR was merged into the 4.0-dev branch. Discussion ---------- [Console] Make SymfonyQuestionHelper::ask optional by default | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes (nothing in core depends on it) | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> i noticed when writing commands i always keep doing ```php $io = new SymfonyStyle($input, $output); $answer = $io->ask('...', null, function ($value) { return $value; }); // instead of just $answer = $io->ask('...'); ``` only to bypass a built-in validation, of which im not sure why it's there. Note the base question helper doesnt make this assumption... Commits ------- 2da429c [Console] Make SymfonyQuestionHelper::ask optional by default
1 parent 44d1162 commit 7695112

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

UPGRADE-3.3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Console
7272
have been deprecated in favor of the `console.error` event and the `ConsoleErrorEvent`
7373
class. The deprecated event and class will be removed in 4.0.
7474

75+
* The `SymfonyQuestionHelper::ask` default validation has been deprecated and will be removed in 4.0. Apply validation using `Question::setValidator` instead.
76+
7577
Debug
7678
-----
7779

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Console
6161
* The `console.exception` event and the related `ConsoleExceptionEvent` class have
6262
been removed in favor of the `console.error` event and the `ConsoleErrorEvent` class.
6363

64+
* The `SymfonyQuestionHelper::ask` default validation has been removed in favor of `Question::setValidator`.
65+
6466
Debug
6567
-----
6668

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
'You can either install it or use the "server:run" command instead.',
9494
));
9595

96-
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) {
96+
if ($io->confirm('Do you want to execute <info>server:run</info> immediately?', false)) {
9797
return $this->getApplication()->find('server:run')->run($input, $output);
9898
}
9999

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CHANGELOG
1818
* deprecated console.exception event in favor of console.error
1919
* added ability to handle `CommandNotFoundException` through the
2020
`console.error` event
21+
* deprecated default validation in `SymfonyQuestionHelper::ask`
2122

2223
3.2.0
2324
------

src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper
2929
{
3030
/**
3131
* {@inheritdoc}
32+
*
33+
* To be removed in 4.0
3234
*/
3335
public function ask(InputInterface $input, OutputInterface $output, Question $question)
3436
{
@@ -39,6 +41,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
3941
} else {
4042
// make required
4143
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
44+
@trigger_error('The default question validator is deprecated since Symfony 3.3 and will not be used anymore in version 4.0. Set a custom question validator if needed.', E_USER_DEPRECATED);
45+
4246
throw new LogicException('A value is required.');
4347
}
4448
}

0 commit comments

Comments
 (0)