@@ -6,8 +6,8 @@ How To Create Symfony Applications with Multiple Kernels
6
6
7
7
In most Symfony applications, incoming requests are processed by the
8
8
``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.
11
11
12
12
This single kernel approach is a convenient default provided by the Symfony
13
13
Standard edition, but Symfony applications can define any number of kernels.
@@ -45,10 +45,8 @@ Step 1) Create a new Front Controller
45
45
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46
46
47
47
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 ``.
52
50
53
51
Then, update the code of the new front controllers to instantiate the new kernel
54
52
class instead of the usual ``AppKernel `` class::
@@ -122,6 +120,24 @@ config files or better, import them and override the needed options:
122
120
123
121
# override option values ...
124
122
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
+
125
141
Adding more Kernels to the Application
126
142
--------------------------------------
127
143
0 commit comments