-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
added example on how to use InputArgument::IS_ARRAY, added overview of a... #2689
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,44 @@ The command can now be used in either of the following ways: | |
$ app/console demo:greet Fabien | ||
$ app/console demo:greet Fabien Potencier | ||
|
||
It is also possible to let an argument take a list of values (imagine you want | ||
to greet all your friends). For this it must be specified at the end of the | ||
argument list:: | ||
|
||
$this | ||
// ... | ||
->addArgument( | ||
'names', | ||
InputArgument::IS_ARRAY, | ||
'Who do you want to greet (separate multiple names with a space)?' | ||
); | ||
|
||
You can now access the ``names`` argument as an array:: | ||
|
||
if ($names = $input->getArgument('names')) { | ||
$text .= ''.implode(', ', $names); | ||
} | ||
|
||
There are 3 argument variants you can use: | ||
|
||
=========================== ================================================================================================= | ||
Option Value | ||
=========================== ================================================================================================= | ||
InputArgument::REQUIRED The argument is required | ||
InputArgument::OPTIONAL The argument is optional and therefore can be omitted | ||
InputArgument::IS_ARRAY Allows to specify an indefinite number of arguments, must be used at the end of the argument list | ||
=========================== ================================================================================================= | ||
|
||
You can combine IS_ARRAY with REQUIRED and OPTIONAL like this:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should put those constants in literals There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same applies to the constants in the options section, doesn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
|
||
$this | ||
// ... | ||
->addArgument( | ||
'names', | ||
InputArgument::IS_ARRAY | InputArgument::REQUIRED, | ||
'Who do you want to greet (separate multiple names with a space)?' | ||
); | ||
|
||
Using Command 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.
''.
is quite useless...