Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thecrypticace
Copy link
Contributor

Currently, it is not possible specify a argument or option name with a hyphen in it (e.g. --dry-run) and have that match a parameter name in the callable like $dryRun.

This is unfortunate because multi-word options are a quite common occurrence in tools.
e.x. the version of rsync I have installed has 57 (!) multi-word options and 39 of those are not aliased.

Also, in some cases (like --dry-run) the wording used is quite common so that's what would be reached for first.

I took some time to create a resolver that will un-hyphenate and lowercase the names before matching against closure parameters to solve this issue.

$this->expressionParser = new ExpressionParser();
$this->invoker = new Invoker();

if ($this->invoker->getParameterResolver() instanceof ResolverChain) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure how to go about this. Would you prefer to be more explicit and specify all the resolvers instead of relying on the default?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes I think it would be better to pass all the resolvers explicitly, that would be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@thecrypticace
Copy link
Contributor Author

An aside to think about: Something else I've come across (though, quite rarely) are options that begin with a number. I don't know if those are common enough to want to support (esp. since you can't start a variable w/ a number in PHP — or most languages for that matter).

@mnapoli
Copy link
Owner

mnapoli commented Aug 25, 2016

Awesome!

Regarding options that start with a number I think it's enough of a edge case to not support it at the moment.

@mnapoli mnapoli merged commit fc0646f into mnapoli:master Aug 31, 2016
@mnapoli
Copy link
Owner

mnapoli commented Aug 31, 2016

Thanks!

mnapoli added a commit that referenced this pull request Aug 31, 2016
@kfriend
Copy link

kfriend commented Sep 5, 2016

This is awesome, thanks for the effort!

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.

3 participants