@@ -229,6 +229,44 @@ The command can now be used in either of the following ways:
229
229
$ app/console demo:greet Fabien
230
230
$ app/console demo:greet Fabien Potencier
231
231
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
+
232
270
Using Command Options
233
271
---------------------
234
272
@@ -297,7 +335,7 @@ InputOption::VALUE_REQUIRED This value is required (e.g. ``--iterations=5``), t
297
335
InputOption::VALUE_OPTIONAL This option may or may not have a value (e.g. ``yell `` or ``yell=loud ``)
298
336
=========================== =====================================================================================
299
337
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:
301
339
302
340
.. code-block :: php
303
341
0 commit comments