4
4
How to Call a Command from a Controller
5
5
=======================================
6
6
7
- The :doc: `Console component documentation </components/console/introduction >` covers
8
- how to create a console command. This cookbook article covers how to use a console command
9
- directly from your controller.
7
+ The :doc: `Console component documentation </components/console/introduction >`
8
+ covers how to create a console command. This cookbook article covers how
9
+ to use a console command directly from your controller.
10
10
11
- You may have the need to execute some function that is only available in a console command.
12
- Usually, you should refactor the command and move some logic into a service that can be
13
- reused in the controller. However, when the command is part of a third-party library, you
14
- wouldn't want to modify or duplicate their code, but want to directly execute the command
15
- instead.
11
+ You may have the need to execute some function that is only available in a
12
+ console command. Usually, you should refactor the command and move some logic
13
+ into a service that can be reused in the controller. However, when the command
14
+ is part of a third-party library, you wouldn't want to modify or duplicate
15
+ their code, but want to directly execute the command instead.
16
16
17
17
.. caution ::
18
18
19
- In comparison with a direct call from the console, calling a command from a controller
20
- has a slight performance impact because of the request stack overhead. This way of
21
- calling a command is only useful for small tasks.
19
+ In comparison with a direct call from the console, calling a command from
20
+ a controller has a slight performance impact because of the request stack
21
+ overhead. This way of calling a command is only useful for small tasks.
22
22
23
23
An example of this is sending the emails that Swift Mailer spooled earlier
24
24
:doc: `using the swiftmailer:spool:send command </cookbook/email/spool >`. Symfony
@@ -58,9 +58,9 @@ allows you to directly execute a registered command inside your controller::
58
58
Showing Colorized Command Output
59
59
--------------------------------
60
60
61
- By telling the ``StreamOutput `` it is decorated via the third parameter, it will return
62
- the Ansi color-coded content. The `SensioLabs AnsiToHtml converter `_ can be required
63
- using ``Composer `` and helps you getting colorful HTML::
61
+ By telling the ``StreamOutput `` it is decorated via the third parameter,
62
+ it will return the Ansi color-coded content. The `SensioLabs AnsiToHtml converter `_
63
+ can be required using ``Composer `` and helps you getting colorful HTML::
64
64
65
65
// src/AppBundle/Controller/SpoolController.php
66
66
namespace AppBundle\Controller;
@@ -79,7 +79,7 @@ using ``Composer`` and helps you getting colorful HTML::
79
79
}
80
80
}
81
81
82
- The ``AnsiToHtmlConverter `` can also be registered `as a Twig Extension `_,
82
+ The ``AnsiToHtmlConverter `` can also be registered `as a Twig Extension `_,
83
83
and supports optional themes.
84
84
85
85
.. _`SensioLabs AnsiToHtml converter` : https://github.com/sensiolabs/ansi-to-html
0 commit comments