Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
blanchonvincent wants to merge2 commits intosymfony:2.7fromblanchonvincent:hotfix/12769
Closed

[Console] Add method to know parsed option#12773

blanchonvincent wants to merge2 commits intosymfony:2.7fromblanchonvincent:hotfix/12769

Conversation

@blanchonvincent
Copy link
Contributor

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#12769,#11572
LicenseMIT
Doc PR-

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe faster with isset ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@samsonasikarray_key_exists is different fromisset. Here, a value can benull

@jakzal
Copy link
Contributor

What's the use case? If the option is not defined why would you like to check if it was passed?

@xabbuh
Copy link
Member

@jakzal The issue is that you can't determine if an option was passed by the user when the value is optional (see#11572 andsymfony/symfony-docs#4110).

@javiereguiluz
Copy link
Member

@xabbuh do you like thehasParsedOption() method name?

@fabpot
Copy link
Member

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 existinggetOption() method.

@bishopb
Copy link

@fabpot I think the challenge with an additional argument togetOption is that wouldn't addressgetOptions, which I would also expect to support tri-state optionals:

command.php$this->getOptions() => [ 'foo' => 'value when not given' ]command.php --foo$this->getOptions() => [ 'foo' => 'value when given but blank' ]command.php --foo=bar$this->getOptions() => [ 'foo' => 'bar' ];

Also, I just noticed changinggetOption contradicts what@stofindicated on a related issue:

Changing getOption() is not possible as it would be a BC break (and would make many valid use cases harder to implement).
However, we could add a new method to check whether the option is present or no (still difficult in term of BC though as we cannot change the InputInterface itself for BC reasons)

@tomzx
Copy link

While you guys are at it, it might also be useful to be able to determine if an argument has been set.

@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 6, 2016
fabpot added a commit that referenced this pull requestMar 1, 2017
…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:![before](http://image.prntscr.com/image/157d9c6c054240da8b0dce54c9ce24d6.png)After:![after](http://image.prntscr.com/image/4aeded77f8084d3c985687fc8cc7b54e.png)Commits-------8086742 [Console] Explicitly passed options without value (or empty) should remain empty
@fabpotfabpot closed thisMar 1, 2017
@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

9 participants

@blanchonvincent@jakzal@xabbuh@javiereguiluz@fabpot@bishopb@tomzx@samsonasik@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp