You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous section, understanding and mastering environments,
4
+
The section:doc:`/cookbook/configuration/environments`
5
5
explained the basics on how Symfony uses environments to run your application
6
6
with different configuration settings. This section will explain a bit more
7
-
in-depth what happens when your application is bootstrapped and how the
8
-
environment it runs in is made up.
9
-
10
-
To fully control this environment, you need to understand three parts that
7
+
in-depth what happens when your application is bootstrapped and how you can hook into this process. You need to understand three parts that
11
8
work together:
9
+
12
10
* The front controller
13
11
* The Kernel class
14
12
* The environment
15
13
16
14
The front controller
17
15
====================
18
16
19
-
A *front controller* is a well-known design pattern; it is a section of
17
+
The [`front controller`](http://en.wikipedia.org/wiki/Front_Controller_pattern) is a well-known design pattern; it is a section of
20
18
code that *all* requests served by an application run through.
21
19
22
-
In the Symfony Standard Edition, this role is taken by the ``app.php`` and
23
-
``app_dev.php`` files in the ``web/`` directory. These are the very first PHP
20
+
In the [Symfony 2 Standard Edition](https://github.com/symfony/symfony-standard), this role is taken by the [``app.php``](https://github.com/symfony/symfony-standard/blob/master/web/app.php) and
21
+
[``app_dev.php``](https://github.com/symfony/symfony-standard/blob/master/web/app_dev.php) files in the ``web/`` directory. These are the very first PHP
24
22
scripts executed when a request is processed.
25
23
26
24
The main purpose of the front controller is to create an instance of the
@@ -29,15 +27,15 @@ return the resulting response to the browser.
29
27
30
28
Because every request is routed through it, the front controller can be used
31
29
to perform global initializations prior to setting up the kernel or to
32
-
*decorate* the kernel with additional features. Examples include:
30
+
[*decorate*](http://en.wikipedia.org/wiki/Decorator_pattern) the kernel with additional features. Examples include:
31
+
33
32
* Configure the autoloader or add additional autoloading mechanisms
34
-
* Add HTTP level caching by wrapping the kernel with an instance of AppCache
* ``registerBundles()``, which must return an array of all bundles needed to
66
+
* :method:`registerBundles()<Symfony\\Component\\HttpKernel\\HttpKernel::registerBundles>`, which must return an array of all bundles needed to
70
67
run the application;
71
-
* ``registerContainerConfiguration()``, which loads the application
68
+
* :method:`registerContainerConfiguration()<Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration>`, which loads the application
72
69
configuration.
73
70
74
-
The Symfony2 Standard Edition comes with a so-called ``AppKernel`` in the
75
-
``app/`` directory (https://github
76
-
.com/symfony/symfony-standard/blob/master/app/AppKernel.php) which fills
77
-
these blanks. This class
78
-
uses the name of the environment, which is passed into the Kernel's
79
-
``__construct()`` method and is available via ``getEnvironment()``,
71
+
To fill these (small) blanks, your application needs to subclass the Kernel
72
+
and implement these methods. The resulting class is called the ``AppKernel``.
73
+
74
+
Again, the Symfony2 Standard Edition provides an [``AppKernel``](https://github
75
+
.com/symfony/symfony-standard/blob/master/app/AppKernel.php) in the
76
+
``app/`` directory. This class
77
+
uses the name of the environment, which is passed to the Kernel's :method:`constructor<Symfony\\Component\\HttpKernel\\Kernel::__construct>` and is available via :method:`getEnvironment()<Symfony\\Component\\HttpKernel\\Kernel::getEnvironment>`,
80
78
to decide which bundles to create in ``registerBundles()``. This method is
81
79
meant to be extended by you when you start adding bundles to your application.
82
80
83
-
You are, of course, free to create alternative or additional
84
-
``AppKernel`` variants. All you need is to adapt (or add a) your front
85
-
controller script to make use of the new kernel. Adding additional kernel
81
+
You are, of course, free to create your own, alternative or additional
82
+
``AppKernel`` variants. All you need is to adapt your (or add a new) front
83
+
controller to make use of the new kernel. Adding additional kernel
86
84
implementations might be useful to
87
-
* easily switch between different set of bundles to work with (without
85
+
86
+
* easily switch between different set of bundles to work with, without
88
87
creating too complicated ``if...else...`` constructs in the ``registerBundles
89
-
()`` method
88
+
()`` method or
90
89
* add more sophisticated ways of loading the application's configuration from
91
90
a different set of files.
92
91
93
92
The environments
94
93
================
95
94
96
-
Environments have been covered extensively in the previous chapter (add link).
97
-
You probably remember that an environment is nothing more than a name (a
95
+
Environments have been covered extensively :doc:`in the previous chapter</cookbook/configuration/environments>`. You probably remember that an environment is nothing more than a name (a
98
96
string) passed to the Kernel's constructor which is in turn used to
99
-
determine which set of configuration files the Kernel is supposed to load.
100
-
101
-
For that, the Standard Edition's ``AppKernel`` class implements the
102
-
``registerContainerConfiguration()`` method to load the
103
-
``app/config/config_*environment*.yml`` file.
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
97
+
determine which set of configuration files the Kernel is supposed to load - and this is what the missing :method:`registerContainerConfiguration()<Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration>` method is used for.
117
98
99
+
The Standard Edition's [``AppKernel``](https://github.com/symfony/symfony-standard/blob/master/app/AppKernel.php) class implements this method by simply loading the ``app/config/config_*environment*.yml`` file.
0 commit comments