From 93ed2e1ab9d79b2e6d84bfe014ce26b50f7aec41 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 3 Jun 2013 20:37:28 +0200 Subject: [PATCH 1/3] added example on how to use InputArgument::IS_ARRAY, added overview of all three argument variants --- components/console/introduction.rst | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index b97b10ce4b6..9ee3488efda 100755 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -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 --------------------- From 9a2efc2f4ca8b143cd90a713a7a3775ecaf6cfcb Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 3 Jun 2013 20:48:47 +0200 Subject: [PATCH 2/3] add missing space --- components/console/introduction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 9ee3488efda..7288312e277 100755 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -244,7 +244,7 @@ argument list:: You can now access the ``names`` argument as an array:: if ($names = $input->getArgument('names')) { - $text .= ''.implode(', ', $names); + $text .= ' '.implode(', ', $names); } There are 3 argument variants you can use: From a5a315a1dcbec19c4f30e54f3c77b5f66fb39a32 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 3 Jun 2013 20:54:15 +0200 Subject: [PATCH 3/3] put class constants within double backticks --- components/console/introduction.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 7288312e277..272781b629b 100755 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -257,7 +257,7 @@ InputArgument::OPTIONAL The argument is optional and therefore can be omitt 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:: +You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this:: $this // ... @@ -335,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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy