44How to Call a Command from a Controller
55=======================================
66
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.
1010
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.
1616
1717.. caution ::
1818
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.
2222
2323An example of this is sending the emails that Swift Mailer spooled earlier
2424: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::
5858Showing Colorized Command Output
5959--------------------------------
6060
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::
6464
6565 // src/AppBundle/Controller/SpoolController.php
6666 namespace AppBundle\Controller;
@@ -79,7 +79,7 @@ using ``Composer`` and helps you getting colorful HTML::
7979 }
8080 }
8181
82- The ``AnsiToHtmlConverter `` can also be registered `as a Twig Extension `_,
82+ The ``AnsiToHtmlConverter `` can also be registered `as a Twig Extension `_,
8383and supports optional themes.
8484
8585.. _`SensioLabs AnsiToHtml converter` : https://github.com/sensiolabs/ansi-to-html
0 commit comments