Skip to content

Commit e403fd8

Browse files
committed
Added a new section about running commands under a different kernel
1 parent af4ff18 commit e403fd8

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

request/multiple_kernels.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ How To Create Symfony Applications with Multiple Kernels
66

77
In most Symfony applications, incoming requests are processed by the
88
``web/app.php`` front controller, which instantiates the ``app/AppKernel.php``
9-
class to create the application kernel that loads the bundles and generates the
10-
response.
9+
class to create the application kernel that loads the bundles and handles the
10+
request to generate the response.
1111

1212
This single kernel approach is a convenient default provided by the Symfony
1313
Standard edition, but Symfony applications can define any number of kernels.
@@ -45,10 +45,8 @@ Step 1) Create a new Front Controller
4545
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4646

4747
Instead of creating the new front controller from scratch, it's recommended to
48-
duplicate the existing ``web/app_dev.php`` and ``web/app.php`` files. For
49-
example, you can create ``web/api_dev.php`` and ``web/api.php`` (or
50-
``web/api/app_dev.php`` and ``web/api/app.php`` depending on your server
51-
configuration).
48+
duplicate the existing ones. For example, create ``web/api_dev.php`` from
49+
``web/app_dev.php`` and ``web/api.php`` from ``web/app.php``.
5250

5351
Then, update the code of the new front controllers to instantiate the new kernel
5452
class instead of the usual ``AppKernel`` class::
@@ -122,6 +120,24 @@ config files or better, import them and override the needed options:
122120
123121
# override option values ...
124122
123+
Executing Commands with a Different Kernel
124+
------------------------------------------
125+
126+
The ``bin/console`` script used to run Symfony commands always uses the default
127+
``AppKernel`` class to build the application and load the commands. If you need
128+
to execute console commands using the new kernel, duplicate the ``bin/console``
129+
script and rename it (e.g. ``bin/api``).
130+
131+
Then, replace the ``AppKernel`` instantiation by your own kernel instantiation
132+
(e.g. ``ApiKernel``) and now you can execute commands using the new kernel
133+
(e.g. ``php bin/api cache:clear``) Now you can use execute commands using the new kernel
134+
135+
.. note::
136+
137+
The commands available for each console script (e.g. ``bin/console`` and
138+
``bin/api``) can differ because they depend on the bundles enabled for each
139+
kernel, which could be different.
140+
125141
Adding more Kernels to the Application
126142
--------------------------------------
127143

0 commit comments

Comments
 (0)