11The Architecture
22================
33
4- You are my hero! Who would have thought that you would still be here after the
5- first three parts? Your efforts will be well rewarded soon. The first three
6- parts didn't look too deeply at the architecture of the framework. Because it
7- makes Symfony stand apart from the framework crowd, let's dive into the
8- architecture now.
4+ You are my hero! Who would have thought that you would still be here after
5+ the first three parts? Your efforts will be well rewarded soon. The first
6+ three parts didn't look too deeply at the architecture of the framework.
7+ Because it makes Symfony stand apart from the framework crowd, let's dive
8+ into the architecture now.
99
1010Understanding the Directory Structure
1111-------------------------------------
@@ -26,7 +26,7 @@ The ``web/`` Directory
2626~~~~~~~~~~~~~~~~~~~~~~
2727
2828The web root directory is the home of all public and static files like images,
29- stylesheets, and JavaScript files. It is also where each :term: `front controller `
29+ stylesheets and JavaScript files. It is also where each :term: `front controller `
3030lives, such as the production controller shown here::
3131
3232 // web/app.php
@@ -57,8 +57,8 @@ configuration and as such, it is stored in the ``app/`` directory.
5757This class must implement two methods:
5858
5959``registerBundles() ``
60- Must return an array of all bundles needed to run the application, as explained
61- in the next section.
60+ Must return an array of all bundles needed to run the application, as
61+ explained in the next section.
6262``registerContainerConfiguration() ``
6363 Loads the application configuration (more on this later).
6464
@@ -74,24 +74,25 @@ Understanding the Bundle System
7474This section introduces one of the greatest and most powerful features of
7575Symfony, the :term: `bundle ` system.
7676
77- A bundle is kind of like a plugin in other software. So why is it called a
78- *bundle * and not a *plugin *? This is because *everything * is a bundle in
79- Symfony, from the core framework features to the code you write for your
80- application.
77+ A bundle is kind of like a plugin in other software. So why is it
78+ called a *bundle * and not a *plugin *? This is because *everything * is a
79+ bundle in Symfony, from the core framework features to the code you write
80+ for your application.
8181
82- All the code you write for your application is organized in bundles. In Symfony
83- speak, a bundle is a structured set of files (PHP files, stylesheets, JavaScripts ,
84- images, ...) that implements a single feature (a blog, a forum, ...) and which
85- can be easily shared with other developers.
82+ All the code you write for your application is organized in bundles. In
83+ Symfony speak, a bundle is a structured set of files (PHP files, stylesheets,
84+ JavaScripts, images, ...) that implements a single feature (a blog, a forum,
85+ ...) and which can be easily shared with other developers.
8686
8787Bundles are first-class citizens in Symfony. This gives you the flexibility
88- to use pre-built features packaged in third-party bundles or to distribute your
89- own bundles. It makes it easy to pick and choose which features to enable in
90- your application and optimize them the way you want. And at the end of the day,
91- your application code is just as *important * as the core framework itself.
92-
93- Symfony already includes an AppBundle that you may use to start developing your
94- application. Then, if you need to split the application into reusable
88+ to use pre-built features packaged in third-party bundles or to distribute
89+ your own bundles. It makes it easy to pick and choose which features to
90+ enable in your application and optimize them the way you want. And at the
91+ end of the day, your application code is just as *important * as the core
92+ framework itself.
93+
94+ Symfony already includes an AppBundle that you may use to start developing
95+ your application. Then, if you need to split the application into reusable
9596components, you can create your own bundles.
9697
9798Registering a Bundle
@@ -125,15 +126,15 @@ a single Bundle class that describes it::
125126 return $bundles;
126127 }
127128
128- In addition to the AppBundle that was already talked about, notice that the
129- kernel also enables other bundles that are part of Symfony, such as FrameworkBundle,
130- DoctrineBundle, SwiftmailerBundle and AsseticBundle.
129+ In addition to the AppBundle that was already talked about, notice that
130+ the kernel also enables other bundles that are part of Symfony, such as
131+ FrameworkBundle, DoctrineBundle, SwiftmailerBundle and AsseticBundle.
131132
132133Configuring a Bundle
133134~~~~~~~~~~~~~~~~~~~~
134135
135- Each bundle can be customized via configuration files written in YAML, XML, or
136- PHP. Have a look at this sample of the default Symfony configuration:
136+ Each bundle can be customized via configuration files written in YAML, XML,
137+ or PHP. Have a look at this sample of the default Symfony configuration:
137138
138139.. code-block :: yaml
139140
@@ -173,14 +174,15 @@ PHP. Have a look at this sample of the default Symfony configuration:
173174
174175 # ...
175176
176- Each first level entry like ``framework ``, ``twig `` and ``swiftmailer `` defines
177- the configuration for a specific bundle. For example, ``framework `` configures
178- the FrameworkBundle while ``swiftmailer `` configures the SwiftmailerBundle.
177+ Each first level entry like ``framework ``, ``twig `` and ``swiftmailer ``
178+ defines the configuration for a specific bundle. For example, ``framework ``
179+ configures the FrameworkBundle while ``swiftmailer `` configures the
180+ SwiftmailerBundle.
179181
180- Each :term: `environment ` can override the default configuration by providing a
181- specific configuration file. For example, the ``dev `` environment loads the
182- ``config_dev.yml `` file, which loads the main configuration (i.e. `` config.yml ``)
183- and then modifies it to add some debugging tools:
182+ Each :term: `environment ` can override the default configuration by providing
183+ a specific configuration file. For example, the ``dev `` environment loads
184+ the ``config_dev.yml `` file, which loads the main configuration (i.e.
185+ `` config.yml ``) and then modifies it to add some debugging tools:
184186
185187.. code-block :: yaml
186188
@@ -202,8 +204,9 @@ Extending a Bundle
202204~~~~~~~~~~~~~~~~~~
203205
204206In addition to being a nice way to organize and configure your code, a bundle
205- can extend another bundle. Bundle inheritance allows you to override any existing
206- bundle in order to customize its controllers, templates, or any of its files.
207+ can extend another bundle. Bundle inheritance allows you to override any
208+ existing bundle in order to customize its controllers, templates, or any
209+ of its files.
207210
208211Logical File Names
209212..................
@@ -226,13 +229,14 @@ For controllers, you need to reference actions using the format
226229Extending Bundles
227230.................
228231
229- If you follow these conventions, then you can use :doc: `bundle inheritance </cookbook/bundles/inheritance >`
230- to override files, controllers or templates. For example, you can create
231- a bundle - NewBundle - and specify that it overrides AppBundle.
232- When Symfony loads the ``AppBundle:Default:index `` controller, it will
233- first look for the ``DefaultController `` class in NewBundle and, if
234- it doesn't exist, then look inside AppBundle. This means that one bundle
235- can override almost any part of another bundle!
232+ If you follow these conventions, then you can use
233+ :doc: `bundle inheritance </cookbook/bundles/inheritance >` to override files,
234+ controllers or templates. For example, you can create a bundle - NewBundle
235+ - and specify that it overrides AppBundle. When Symfony loads the
236+ ``AppBundle:Default:index `` controller, it will first look for the
237+ ``DefaultController `` class in NewBundle and, if it doesn't exist, then
238+ look inside AppBundle. This means that one bundle can override almost any
239+ part of another bundle!
236240
237241Do you understand now why Symfony is so flexible? Share your bundles between
238242applications, store them locally or globally, your choice.
@@ -245,37 +249,40 @@ Using Vendors
245249Odds are that your application will depend on third-party libraries. Those
246250should be stored in the ``vendor/ `` directory. You should never touch anything
247251in this directory, because it is exclusively managed by Composer. This directory
248- already contains the Symfony libraries, the SwiftMailer library, the Doctrine ORM,
249- the Twig templating system and some other third party libraries and bundles.
252+ already contains the Symfony libraries, the SwiftMailer library, the Doctrine
253+ ORM, the Twig templating system and some other third party libraries and
254+ bundles.
250255
251256Understanding the Cache and Logs
252257--------------------------------
253258
254- Symfony applications can contain several configuration files defined in several
255- formats (YAML, XML, PHP, etc.) Instead of parsing and combining all those files
256- for each request, Symfony uses its own cache system. In fact, the application
257- configuration is only parsed for the very first request and then compiled down
258- to plain PHP code stored in the ``app/cache/ `` directory.
259+ Symfony applications can contain several configuration files defined in
260+ several formats (YAML, XML, PHP, etc.) Instead of parsing and combining
261+ all those files for each request, Symfony uses its own cache system. In
262+ fact, the application configuration is only parsed for the very first request
263+ and then compiled down to plain PHP code stored in the ``app/cache/ ``
264+ directory.
259265
260- In the development environment, Symfony is smart enough to update the cache when
261- you change a file. But in the production environment, to speed things up, it is
262- your responsibility to clear the cache when you update your code or change its
263- configuration. Execute this command to clear the cache in the ``prod `` environment:
266+ In the development environment, Symfony is smart enough to update the cache
267+ when you change a file. But in the production environment, to speed things
268+ up, it is your responsibility to clear the cache when you update your code
269+ or change its configuration. Execute this command to clear the cache in
270+ the ``prod `` environment:
264271
265272.. code-block :: bash
266273
267274 $ php app/console cache:clear --env=prod
268275
269- When developing a web application, things can go wrong in many ways. The log
270- files in the ``app/logs/ `` directory tell you everything about the requests
276+ When developing a web application, things can go wrong in many ways. The
277+ log files in the ``app/logs/ `` directory tell you everything about the requests
271278and help you fix the problem quickly.
272279
273280Using the Command Line Interface
274281--------------------------------
275282
276283Each application comes with a command line interface tool (``app/console ``)
277- that helps you maintain your application. It provides commands that boost your
278- productivity by automating tedious and repetitive tasks.
284+ that helps you maintain your application. It provides commands that boost
285+ your productivity by automating tedious and repetitive tasks.
279286
280287Run it without any arguments to learn more about its capabilities:
281288
@@ -299,7 +306,7 @@ around as you see fit.
299306
300307And that's all for the quick tour. From testing to sending emails, you still
301308need to learn a lot to become a Symfony master. Ready to dig into these
302- topics now? Look no further - go to the official :doc: `/book/index ` and pick
303- any topic you want.
309+ topics now? Look no further - go to the official :doc: `/book/index ` and
310+ pick any topic you want.
304311
305312.. _Composer : http://getcomposer.org
0 commit comments