Skip to content

[Console] Make SymfonyQuestionHelper::ask optional by default #22317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

[Console] Make SymfonyQuestionHelper::ask optional by default #22317

wants to merge 1 commit into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Apr 6, 2017

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

$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...

@chalasr
Copy link
Member

chalasr commented Apr 6, 2017

👍 Already pointed out in #20141 when making it more flexible, I don't know why this default validator has been added, console's Symfony* stuff should only be about output styling, not input filtering.

@@ -29,6 +29,8 @@ class SymfonyQuestionHelper extends QuestionHelper
{
/**
* {@inheritdoc}
*
* @deprecated since version 3.3, to be removed in 4.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this.. it creates some nasty strikethroughs in IDE's, and the same method call will work in 4.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think I would talk only about the removed validation. Btw this needs to be documented :)

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Apr 7, 2017
@nicolas-grekas
Copy link
Member

Moving to milestone 3.4 as this is not a blocker for 3.3. If you don't agree, please tell :)

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.4 Apr 28, 2017
@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 28, 2017

Just annoying :) 👍 for 3.4, im used doing this already.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target should also be changed to 3.4.

UPGRADE-3.3.md Outdated
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to 3.4.

@@ -39,6 +41,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
} 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.4 instead of 3.3

@ro0NL ro0NL changed the base branch from master to 3.4 July 20, 2017 18:57
fabpot added a commit that referenced this pull request Jul 20, 2017
…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
chalasr pushed a commit to chalasr/symfony that referenced this pull request Jul 22, 2017
…nal 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
@chalasr
Copy link
Member

chalasr commented Jul 22, 2017

Thank you @ro0NL

@chalasr chalasr closed this Jul 22, 2017
@ro0NL ro0NL deleted the console/sf-question branch July 22, 2017 18:56
@@ -39,6 +41,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
} else {
// make required
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
@trigger_error('The default question validator is deprecated since Symfony 3.4 and will not be used anymore in version 4.0. Set a custom question validator instead.', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ro0NL is this really in the correct code path? Throwing both a deprecation and an exception is suspicious to me.

Copy link
Member

@chalasr chalasr Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

Copy link
Contributor Author

@ro0NL ro0NL Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're deprecating the fact this exception is thrown when the value is blank. Meaning in 4.0 ask() is optional by default, whereas now it's required by default.

I actually considered putting the trigger above if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {, but its weird to get the deprecation for a case that is still valid in 4.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think it's the right place for this deprecation.

nicolas-grekas added a commit that referenced this pull request Jul 26, 2017
* 3.4:
  [DI] use assertStringEqualsFile when possible
  [VarDumper] Adapt to php 7.2 changes
  [DI] Fix using private services in expressions
  [Form][TwigBridge] Don't render _method in form_rest() for a child form
  [Form] Static call TimezoneType::getTimezones
  Removed references for non existent validator constraints
  Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS
  [DI] Fix test
  [Cache] Handle unserialization failures for Memcached
  Remove unused prop + added @deprecated
  Remove unused mocks/vars
  feature #22317 [Console] Make SymfonyQuestionHelper::ask optional by default (ro0NL)
  [DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables
  [Validator] Fix IbanValidator for ukrainian IBANs
  Router: allow HEAD method to be defined first
  [WebProfilerBundle] Display trace and context in the logger profiler
  Fixing a bug where if a core class was autowired, autowiring tried to autowire optional args as if they were required
@fabpot fabpot mentioned this pull request Oct 19, 2017
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
* 3.4:
  [DI] use assertStringEqualsFile when possible
  [VarDumper] Adapt to php 7.2 changes
  [DI] Fix using private services in expressions
  [Form][TwigBridge] Don't render _method in form_rest() for a child form
  [Form] Static call TimezoneType::getTimezones
  Removed references for non existent validator constraints
  Suggest using quotes instead of Yaml::PARSE_KEYS_AS_STRINGS
  [DI] Fix test
  [Cache] Handle unserialization failures for Memcached
  Remove unused prop + added @deprecated
  Remove unused mocks/vars
  feature symfony#22317 [Console] Make SymfonyQuestionHelper::ask optional by default (ro0NL)
  [DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables
  [Validator] Fix IbanValidator for ukrainian IBANs
  Router: allow HEAD method to be defined first
  [WebProfilerBundle] Display trace and context in the logger profiler
  Fixing a bug where if a core class was autowired, autowiring tried to autowire optional args as if they were required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants