Skip to content

Commit f45c392

Browse files
94noniwouterj
authored andcommitted
[Console] Command Lifecycle explications
1 parent 9fb296d commit f45c392

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

components/console/introduction.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ This prints::
110110

111111
HELLO FABIEN
112112

113+
Command Lifecycle
114+
~~~~~~~~~~~~~~~~~
115+
116+
Commands have three lifecycle methods:
117+
118+
:method:`Symfony\\Component\\Console\\Command\\Command::initialize`
119+
This method is executed before the ``interact()`` and the ``execute()``
120+
methods. It's main purpose is to initialize the variables used in the
121+
rest of the command methods.
122+
123+
:method:`Symfony\\Component\\Console\\Command\\Command::interact`
124+
This method is executed after ``initialize()`` and before ``execute()``.
125+
Its purpose is to check if some of the options/arguments are missing
126+
and interactively ask the user for those values. This is the last place
127+
where you can ask for missing options/arguments otherwise the command
128+
will throw an error.
129+
130+
:method:`Symfony\\Component\\Console\\Command\\Command::execute`
131+
This method is executed after ``interact()`` and ``initialize()``.
132+
It contains the logic you want the command executes.
133+
134+
Note that ``execute()`` is the only required method of the three.
135+
136+
The ``initialize()`` and ``interact()`` methods are completely optional.
137+
113138
.. _components-console-coloring:
114139

115140
Coloring the Output

0 commit comments

Comments
 (0)