File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed 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:
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
You can’t perform that action at this time.
0 commit comments