8000 added example on how to use InputArgument::IS_ARRAY, added overview of a... by xabbuh · Pull Request #2689 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 3 commits into from
Jun 4, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion components/console/introduction.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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::

$this
// ...
->addArgument(
'names',
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Who do you want to greet (separate multiple names with a space)?'
);

Using Command Options
---------------------

Expand Down Expand Up @@ -297,7 +335,7 @@ InputOption::VALUE_REQUIRED This value is required (e.g. ``--iterations=5``), t
InputOption::VALUE_OPTIONAL This option may or may not have a value (e.g. ``yell`` or ``yell=loud``)
=========================== =====================================================================================

You can combine VALUE_IS_ARRAY with VALUE_REQUIRED or VALUE_OPTIONAL like this:
You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or ``VALUE_OPTIONAL`` like this:

.. code-block:: php

Expand Down
0