-
Notifications
You must be signed in to change notification settings - Fork 2k
Use CLI::getSegment(2) to refer to the first argument of generator command #3585
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
|
I think this should be getSegment(2). |
michalsn
left a comment
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.
Just waiting for tests to pass before merging.
MGatner
left a comment
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.
Could we get a test case showing what this fixes? How has this been working so far?
Unfortunately, I think we cannot setup an automated test for this. The concrete classes extending GeneratorCommand all require class names as argument, so the empty string given here will trigger a Analyzing how CLI parses the arguments and stores them, here is an illustration: php spark make:controller blog -bare
CLI::getSegment(0) =>> undefined // since we are accessing the -1 index
CLI::getSegment(1) =>> 'make:command' // first segment after the name of invoking program is the name of the command
CLI::getSegment(2) =>> 'blog' // next segments would be the arguments passed to the command
CLI::getOption('bare') =>> true // since it is set as a flag |
|
All good! I trust your assessment. |
|
I have just been working on my dynamic menu system and had to count($uri->getSegments()) to prevent the following error being thrown: // $tmpSub = $uri->getSegment(2) // MAYBE THROW ERRORRequest URI segment is out of range: Online Demo using $uri->getSegment(2) : |
|
@John-Betong You can use |
That's new to me and could come in handy some time in the future. I don' think I like hiding exceptions, far prefer to know what is happening. I prefer testing for results and using if/else/endif statements. |
Description
I've noticed that
getSegment's code deducts 1 from the index parameter before checking which made me realize that it is one-based instead of zero-based. This PR updatesGeneratorCommand::getClassName()to use that.In retrospect, why was it that way?
Checklist: