From 76951126013abbd5dc36af43aaa0185f8318a265 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 20 Jul 2017 19:25:39 +0200 Subject: [PATCH] feature #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 | #... | License | MIT | Doc PR | symfony/symfony-docs#... 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 ------- 2da429cd0a [Console] Make SymfonyQuestionHelper::ask optional by default --- UPGRADE-3.3.md | 2 ++ UPGRADE-4.0.md | 2 ++ .../Bundle/WebServerBundle/Command/ServerStartCommand.php | 2 +- src/Symfony/Component/Console/CHANGELOG.md | 1 + .../Component/Console/Helper/SymfonyQuestionHelper.php | 4 ++++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index b8d2524654..7f61c71f57 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -72,6 +72,8 @@ Console have been deprecated in favor of the `console.error` event and the `ConsoleErrorEvent` class. The deprecated event and class will be removed in 4.0. + * The `SymfonyQuestionHelper::ask` default validation has been deprecated and will be removed in 4.0. Apply validation using `Question::setValidator` instead. + Debug ----- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index ca1f8f10e1..32248ac4e0 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -61,6 +61,8 @@ Console * The `console.exception` event and the related `ConsoleExceptionEvent` class have been removed in favor of the `console.error` event and the `ConsoleErrorEvent` class. + * The `SymfonyQuestionHelper::ask` default validation has been removed in favor of `Question::setValidator`. + Debug ----- diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php index 57de788608..af90a53f32 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php @@ -93,7 +93,7 @@ EOF 'You can either install it or use the "server:run" command instead.', )); - if ($io->ask('Do you want to execute server:run immediately? [yN] ', false)) { + if ($io->confirm('Do you want to execute server:run immediately?', false)) { return $this->getApplication()->find('server:run')->run($input, $output); } diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index b337ecf992..616f70e137 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -18,6 +18,7 @@ CHANGELOG * deprecated console.exception event in favor of console.error * added ability to handle `CommandNotFoundException` through the `console.error` event +* deprecated default validation in `SymfonyQuestionHelper::ask` 3.2.0 ------ diff --git a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php index 25e094a04f..cf071d594d 100644 --- a/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php @@ -29,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper { /** * {@inheritdoc} + * + * To be removed in 4.0 */ public function ask(InputInterface $input, OutputInterface $output, Question $question) { @@ -39,6 +41,8 @@ class SymfonyQuestionHelper extends QuestionHelper } else { // make required if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) { + @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); + throw new LogicException('A value is required.'); } }