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

Appearance settings

Commit ba7fda0

Browse filesBrowse files
committed
Merge pull request #2689 from xabbuh/issue-2686
added example on how to use InputArgument::IS_ARRAY, added overview of a...
2 parents d484713 + a5a315a commit ba7fda0
Copy full SHA for ba7fda0

File tree

Expand file treeCollapse file tree

1 file changed

+39
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+39
-1
lines changed

‎components/console/introduction.rst

Copy file name to clipboardExpand all lines: components/console/introduction.rst
+39-1Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,44 @@ The command can now be used in either of the following ways:
229229
$ app/console demo:greet Fabien
230230
$ app/console demo:greet Fabien Potencier
231231
232+
It is also possible to let an argument take a list of values (imagine you want
233+
to greet all your friends). For this it must be specified at the end of the
234+
argument list::
235+
236+
$this
237+
// ...
238+
->addArgument(
239+
'names',
240+
InputArgument::IS_ARRAY,
241+
'Who do you want to greet (separate multiple names with a space)?'
242+
);
243+
244+
You can now access the ``names`` argument as an array::
245+
246+
if ($names = $input->getArgument('names')) {
247+
$text .= ' '.implode(', ', $names);
248+
}
249+
250+
There are 3 argument variants you can use:
251+
252+
=========================== =================================================================================================
253+
Option Value
254+
=========================== =================================================================================================
255+
InputArgument::REQUIRED The argument is required
256+
InputArgument::OPTIONAL The argument is optional and therefore can be omitted
257+
InputArgument::IS_ARRAY Allows to specify an indefinite number of arguments, must be used at the end of the argument list
258+
=========================== =================================================================================================
259+
260+
You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this::
261+
262+
$this
263+
// ...
264+
->addArgument(
265+
'names',
266+
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
267+
'Who do you want to greet (separate multiple names with a space)?'
268+
);
269+
232270
Using Command Options
233271
---------------------
234272

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

300-
You can combine VALUE_IS_ARRAY with VALUE_REQUIRED or VALUE_OPTIONAL like this:
338+
You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or ``VALUE_OPTIONAL`` like this:
301339

302340
.. code-block:: php
303341

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.