-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add method to know parsed option #12773
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
Conversation
blanchonvincent
commented
Nov 30, 2014
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #12769, #11572 |
License | MIT |
Doc PR | - |
*/ | ||
public function hasParsedOption($name) | ||
{ | ||
return array_key_exists($name, $this->options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe faster with isset ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samsonasik array_key_exists
is different from isset
. Here, a value can be null
What's the use case? If the option is not defined why would you like to check if it was passed? |
@jakzal The issue is that you can't determine if an option was passed by the user when the value is optional (see #11572 and symfony/symfony-docs#4110). |
@xabbuh do you like the |
I think the implementation should be actually different. There is no need to add another method with a weird name nobody will understand. I was more thinking about adding an additional argument to the existing |
@fabpot I think the challenge with an additional argument to
Also, I just noticed changing
|
While you guys are at it, it might also be useful to be able to determine if an argument has been set. |
…empty) should remain empty (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Explicitly passed options without value (or empty) should remain empty | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21215 #11572 #12773 | License | MIT | Doc PR | n/a (maybe look at updating the existing one) This conserves empty values for options instead of returning their default values. Code: ```php // cli.php $application = new Application(); $application ->register('echo') ->addOption('prefix', null, InputOption::VALUE_OPTIONAL, null, 'my-default') ->addArgument('value', InputArgument::REQUIRED) ->setCode(function ($input, $output) { var_dump($input->getOption('prefix')); }); $application->run(); ``` Before:  After:  Commits ------- 8086742 [Console] Explicitly passed options without value (or empty) should remain empty