Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit93ed2e1

Browse files
committed
added example on how to use InputArgument::IS_ARRAY, added overview of all three argument variants
1 parent606f660 commit93ed2e1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎components/console/introduction.rst

Lines changed: 38 additions & 0 deletions
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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp