Skip to content

Commit 34ab029

Browse files
mpdudeweaverryan
authored andcommitted
Some updates
1 parent a2e925b commit 34ab029

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed
Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
Understanding how Front Controller, Kernel and Environments work together
22
=========================================================================
33

4-
The previous section, understanding and mastering environments,
4+
The section :doc:`/cookbook/configuration/environments`
55
explained the basics on how Symfony uses environments to run your application
66
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
118
work together:
9+
1210
* The front controller
1311
* The Kernel class
1412
* The environment
1513

1614
The front controller
1715
====================
1816

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
2018
code that *all* requests served by an application run through.
2119

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
2422
scripts executed when a request is processed.
2523

2624
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.
2927

3028
Because every request is routed through it, the front controller can be used
3129
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+
3332
* Configure the autoloader or add additional autoloading mechanisms
34-
* Add HTTP level caching by wrapping the kernel with an instance of AppCache
35-
(http://symfony.com/doc/2.0/book/http_cache.html#symfony2-reverse-proxy)
36-
* Enabling the Debug component (add link)
33+
* Add HTTP level caching by wrapping the kernel with an instance of :doc:`AppCache</book/http_cache#symfony2-reverse-proxy>`
34+
* Enabling the [Debug component](https://github.com/symfony/symfony/pull/7441)
3735

38-
When using Apache and the RewriteRule (https://github
39-
.com/symfony/symfony-standard/blob/master/web/.htaccess) shipped with the
40-
Standard Edition, the front controller can be chosen by requesting URLs like
36+
When using Apache and the [RewriteRule shipped with the
37+
Standard Edition](https://github
38+
.com/symfony/symfony-standard/blob/master/web/.htaccess), the front controller can be chosen by requesting URLs like::
4139

4240
http://localhost/app_dev.php/some/path/...
4341

@@ -47,7 +45,7 @@ or use a custom one by placing it in the ``web/`` directory. If the front
4745
controller file is missing from the URL, the RewriteRule will use ``app
4846
.php`` as the default one.
4947

50-
Technically, the ``app/console`` script (https://github
48+
Technically, the [``app/console`` script](https://github
5149
.com/symfony/symfony-standard/blob/master/app/console) used when running
5250
Symfony on the command line is also a front controller,
5351
only that is not used for web, but for command line requests.
@@ -60,58 +58,42 @@ setting up all the bundles that make up your application and providing them
6058
with the application's configuration. It then creates the service container
6159
before serving requests in its ``handle()`` method.
6260

63-
There are two methods related to the first two of these steps which the base
64-
HttpKernel
65-
(https://github
61+
There are two methods related to the first two of these steps which [the base
62+
HttpKernel](https://github
6663
.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/HttpKernel
6764
.php) does not implement:
6865

69-
* ``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
7067
run the application;
71-
* ``registerContainerConfiguration()``, which loads the application
68+
* :method:`registerContainerConfiguration()<Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration>`, which loads the application
7269
configuration.
7370

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>`,
8078
to decide which bundles to create in ``registerBundles()``. This method is
8179
meant to be extended by you when you start adding bundles to your application.
8280

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
8684
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
8887
creating too complicated ``if...else...`` constructs in the ``registerBundles
89-
()`` method
88+
()`` method or
9089
* add more sophisticated ways of loading the application's configuration from
9190
a different set of files.
9291

9392
The environments
9493
================
9594

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
9896
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.
11798

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

Comments
 (0)