From c78eaa53fdc02fb4fd5f3980fc33fb8641781fb2 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Tue, 26 May 2015 10:29:32 +0200 Subject: [PATCH 1/4] [Console] Command Lifecycle explications --- components/console/introduction.rst | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index eda67260924..055e552303c 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -110,6 +110,37 @@ This prints:: HELLO FABIEN +Command Lifecycle +~~~~~~~~~~~~~~~~ + +Commands have 3 lifecycle methods: + + 1. initialize($input, $output) + 2. interact($input, $output) + 3. execute($input, $output) + +Explications: + + initialize($input, $output) + +This method is executed before the interact() and the execute() methods. +It's main purpose is to initialize the variables used in the rest of +the command methods. + + interact($input, $output) + +This method is executed after initialize() and before execute(). Its purpose +is to check if some of the options/arguments are missing and interactively +ask the user for those values. + + execute($input, $output) + +This method is executed after interact() and initialize(). It usually +contains the logic to execute to complete this command task. + +Note that ``initialize($input, $output)`` and ``interact($input, $output)`` +methods are completely optional. + .. _components-console-coloring: Coloring the Output From 3ca7c37b3a9920116ab348bbe023d6fcdafd548b Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Tue, 26 May 2015 10:35:48 +0200 Subject: [PATCH 2/4] fix --- components/console/introduction.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 055e552303c..8af9f128e84 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -111,7 +111,7 @@ This prints:: HELLO FABIEN Command Lifecycle -~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~ Commands have 3 lifecycle methods: @@ -119,7 +119,7 @@ Commands have 3 lifecycle methods: 2. interact($input, $output) 3. execute($input, $output) -Explications: +Explanations: initialize($input, $output) @@ -138,7 +138,8 @@ ask the user for those values. This method is executed after interact() and initialize(). It usually contains the logic to execute to complete this command task. -Note that ``initialize($input, $output)`` and ``interact($input, $output)`` +Note that ``execute($input, $output)`` is the only required method of the three. +``initialize($input, $output)`` and ``interact($input, $output)`` methods are completely optional. .. _components-console-coloring: From 6abe3b1b70f9b4e6864e1d87c307d069f60c9075 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Mon, 1 Jun 2015 08:37:01 +0200 Subject: [PATCH 3/4] fix style --- components/console/introduction.rst | 35 ++++++++++++----------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 8af9f128e84..547307e9fe2 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -113,34 +113,27 @@ This prints:: Command Lifecycle ~~~~~~~~~~~~~~~~~ -Commands have 3 lifecycle methods: +Commands have three lifecycle methods: - 1. initialize($input, $output) - 2. interact($input, $output) - 3. execute($input, $output) +:method:`Symfony\\Component\\Console\\Command\\Command::initialize` -Explanations: + This method is executed before the ``interact()`` and the ``execute()`` + methods. It's main purpose is to initialize the variables used in the + rest of the command methods. - initialize($input, $output) +:method:`Symfony\\Component\\Console\\Command\\Command::interact` -This method is executed before the interact() and the execute() methods. -It's main purpose is to initialize the variables used in the rest of -the command methods. + This method is executed after ``initialize()`` and before ``execute()``. + Its purpose is to check if some of the options/arguments are missing + and interactively ask the user for those values. - interact($input, $output) +:method:`Symfony\\Component\\Console\\Command\\Command::execute` -This method is executed after initialize() and before execute(). Its purpose -is to check if some of the options/arguments are missing and interactively -ask the user for those values. + This method is executed after ``interact()`` and ``initialize()``. It + usually contains the logic to execute to complete this command task. - execute($input, $output) - -This method is executed after interact() and initialize(). It usually -contains the logic to execute to complete this command task. - -Note that ``execute($input, $output)`` is the only required method of the three. -``initialize($input, $output)`` and ``interact($input, $output)`` -methods are completely optional. + Note that ``execute()`` is the only required method of the three. The + ``initialize()`` and ``interact()`` methods are completely optional. .. _components-console-coloring: From 0faae4a8bad437c5411a6f0330d2a1fedb22a149 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Tue, 2 Jun 2015 09:44:25 +0200 Subject: [PATCH 4/4] fix --- components/console/introduction.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 547307e9fe2..8f68a5c7d66 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -116,24 +116,24 @@ Command Lifecycle Commands have three lifecycle methods: :method:`Symfony\\Component\\Console\\Command\\Command::initialize` - This method is executed before the ``interact()`` and the ``execute()`` methods. It's main purpose is to initialize the variables used in the rest of the command methods. :method:`Symfony\\Component\\Console\\Command\\Command::interact` - This method is executed after ``initialize()`` and before ``execute()``. Its purpose is to check if some of the options/arguments are missing - and interactively ask the user for those values. + and interactively ask the user for those values. This is the last place + where you can ask for missing options/arguments otherwise the command + will throw an error. :method:`Symfony\\Component\\Console\\Command\\Command::execute` + This method is executed after ``interact()`` and ``initialize()``. + It contains the logic you want the command executes. - This method is executed after ``interact()`` and ``initialize()``. It - usually contains the logic to execute to complete this command task. +Note that ``execute()`` is the only required method of the three. - Note that ``execute()`` is the only required method of the three. The - ``initialize()`` and ``interact()`` methods are completely optional. +The ``initialize()`` and ``interact()`` methods are completely optional. .. _components-console-coloring: