-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Console] Command Lifecycle explications #5319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,31 @@ This prints:: | |
|
||
HELLO FABIEN | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add that this method is executed before the input definition is validated. This means that this is the only place where you can ask for missing options, otherwise the command throw an error about missing options. |
||
|
||
:method:`Symfony\\Component\\Console\\Command\\Command::execute` | ||
|
||
This method is executed after ``interact()`` and ``initialize()``. It | ||
usually contains the logic to execute to complete this command task. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to remove "to complete" to make this readable I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok of course, |
||
|
||
Note that ``execute()`` is the only required method of the three. The | ||
``initialize()`` and ``interact()`` methods are completely optional. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put this as a normal paragraph again (without indentation) |
||
|
||
.. _components-console-coloring: | ||
|
||
Coloring the Output | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this empty line between term and definition is not allowed