@@ -114,7 +114,7 @@ That array told symfony1 exactly which file contained each class. In the
114114production environment, this caused you to need to clear the cache when classes
115115were added or moved.
116116
117- In Symfony2, anew class - `` UniversalClassLoader `` - handles this process.
117+ In Symfony2, atool named ` Composer `_ handles this process.
118118The idea behind the autoloader is simple: the name of your class (including
119119the namespace) must match up with the path to the file containing that class.
120120Take the ``FrameworkExtraBundle `` from the Symfony2 Standard Edition as an
@@ -136,18 +136,7 @@ As you can see, the location of the file follows the namespace of the class.
136136Specifically, the namespace, ``Sensio\Bundle\FrameworkExtraBundle ``, spells out
137137the directory that the file should live in
138138(``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/ ``).
139- This is because, in the ``app/autoload.php `` file, you'll configure Symfony to
140- look for the ``Sensio `` namespace in the ``vendor/sensio `` directory:
141-
142- ..code-block ::php
143-
144- // app/autoload.php
145-
146- // ...
147- $loader->registerNamespaces(array(
148- ...,
149- 'Sensio' => __DIR__.'/../vendor/sensio/framework-extra-bundle',
150- ));
139+ Composer can then look for the file at this specific place and load it very fast.
151140
152141If the file did *not * live at this exact location, you'd receive a
153142``Class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" does not exist. ``
@@ -160,24 +149,24 @@ contains a different class). In order for a class to be autoloaded, you
160149As mentioned before, for the autoloader to work, it needs to know that the
161150``Sensio `` namespace lives in the ``vendor/bundles `` directory and that, for
162151example, the ``Doctrine `` namespace lives in the ``vendor/doctrine/orm/lib/ ``
163- directory. This mapping is entirely controlled by you via the
164- ``app/autoload.php `` file.
152+ directory. This mapping is entirely controlled by Composer. Each
153+ third-party library you load through composer has their settings defined
154+ and Composer takes care of everything for you.
155+
156+ For this to work, all third-party libraries used by your project must be
157+ defined in the `composer.json ` file.
165158
166159If you look at the ``HelloController `` from the Symfony2 Standard Edition you
167160can see that it lives in the ``Acme\DemoBundle\Controller `` namespace. Yet, the
168- ``Acme `` namespace is not defined in the ``app/autoload.php ``. By default you
169- do not need to explicitly configure the location of bundles that live in the
170- ``src/ `` directory. The ``UniversalClassLoader `` is configured to fallback to
171- the ``src/ `` directory using its ``registerNamespaceFallbacks `` method:
161+ ``AcmeDemoBundle `` is not defined in your `composer.json ` file. Nonetheless are
162+ the files autoloaded. This is because you can tell composer to autoload files
163+ from specific directories without defining a dependency:
172164
173- ..code-block ::php
174-
175- // app/autoload.php
165+ ..code-block ::yaml
176166
177- // ...
178- $loader->registerNamespaceFallbacks(array(
179- __DIR__.'/../src',
180- ));
167+ " autoload " :{
168+ " psr-0 " :{ "": "src/" }
169+ }
181170
182171 Using the Console
183172-----------------
@@ -312,3 +301,4 @@ primarily to configure objects that you can use. For more information, see
312301the chapter titled ":doc: `/book/service_container `".
313302
314303.. _`Symfony2 Standard` :https://github.com/symfony/symfony-standard
304+ .. _`Composer` :http://getcomposer.org