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 | #... <!-- #-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
-------

2da429cd0a [Console] Make SymfonyQuestionHelper::ask optional by default
This commit is contained in:
Fabien Potencier 2017-07-20 19:25:39 +02:00 committed by Robin Chalas
parent 44d1162df4
commit 7695112601
5 changed files with 10 additions and 1 deletions

View File

@ -72,6 +72,8 @@ Console
have been deprecated in favor of the `console.error` event and the `ConsoleErrorEvent` 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. 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 Debug
----- -----

View File

@ -61,6 +61,8 @@ Console
* The `console.exception` event and the related `ConsoleExceptionEvent` class have * The `console.exception` event and the related `ConsoleExceptionEvent` class have
been removed in favor of the `console.error` event and the `ConsoleErrorEvent` class. 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 Debug
----- -----

View File

@ -93,7 +93,7 @@ EOF
'You can either install it or use the "server:run" command instead.', 'You can either install it or use the "server:run" command instead.',
)); ));
if ($io->ask('Do you want to execute <info>server:run</info> immediately? [yN] ', false)) { if ($io->confirm('Do you want to execute <info>server:run</info> immediately?', false)) {
return $this->getApplication()->find('server:run')->run($input, $output); return $this->getApplication()->find('server:run')->run($input, $output);
} }

View File

@ -18,6 +18,7 @@ CHANGELOG
* deprecated console.exception event in favor of console.error * deprecated console.exception event in favor of console.error
* added ability to handle `CommandNotFoundException` through the * added ability to handle `CommandNotFoundException` through the
`console.error` event `console.error` event
* deprecated default validation in `SymfonyQuestionHelper::ask`
3.2.0 3.2.0
------ ------

View File

@ -29,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* To be removed in 4.0
*/ */
public function ask(InputInterface $input, OutputInterface $output, Question $question) public function ask(InputInterface $input, OutputInterface $output, Question $question)
{ {
@ -39,6 +41,8 @@ class SymfonyQuestionHelper extends QuestionHelper
} else { } else {
// make required // make required
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) { 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.'); throw new LogicException('A value is required.');
} }
} }