Skip to content

Commit 93c09e5

Browse files
committed
Merge remote-tracking branch 'origin/2.1' into 2.1
2 parents fe95b26 + c6cb402 commit 93c09e5

File tree

3 files changed

+22
-38
lines changed

3 files changed

+22
-38
lines changed

book/internals.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on top of the previous one.
2323

2424
Autoloading is not managed by the framework directly; it's done by using
2525
Composer's autoloader (``vendor/autoload.php``), which is included in
26-
the ``src/autoload.php`` file.
26+
the ``app/autoload.php`` file.
2727

2828
``HttpFoundation`` Component
2929
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

book/page_creation.rst

+5-11
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ You'll learn more about each of these directories in later chapters.
512512

513513
.. sidebar:: Autoloading
514514

515-
When Symfony is loading, a special file - ``app/autoload.php`` - is included.
516-
This file is responsible for configuring the autoloader, which will autoload
517-
your application files from the ``src/`` directory and third-party libraries
518-
from the ``vendor/`` directory.
515+
When Symfony is loading, a special file - ``vendor/autoload.php`` - is
516+
included. This file is created by Composer and will autoload all
517+
application files living in the `src/` folder as well as all
518+
third-party libraries mentioned in the ``composer.json`` file.
519519

520520
Because of the autoloader, you never need to worry about using ``include``
521-
or ``require`` statements. Instead, Symfony2 uses the namespace of a class
521+
or ``require`` statements. Instead, Composer uses the namespace of a class
522522
to determine its location and automatically includes the file on your
523523
behalf the instant you need a class.
524524

@@ -533,11 +533,6 @@ You'll learn more about each of these directories in later chapters.
533533
Path:
534534
src/Acme/HelloBundle/Controller/HelloController.php
535535
536-
Typically, the only time you'll need to worry about the ``app/autoload.php``
537-
file is when you're including a new third-party library in the ``vendor/``
538-
directory. For more information on autoloading, see
539-
:doc:`How to autoload Classes</components/class_loader>`.
540-
541536
The Source (``src``) Directory
542537
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
543538

@@ -609,7 +604,6 @@ are used by your application (including the core Symfony bundles).
609604

610605
A bundle can live *anywhere* as long as it can be autoloaded (via the
611606
autoloader configured at ``app/autoload.php``).
612-
613607
Creating a Bundle
614608
~~~~~~~~~~~~~~~~~
615609

cookbook/symfony1.rst

+16-26
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ That array told symfony1 exactly which file contained each class. In the
114114
production environment, this caused you to need to clear the cache when classes
115115
were added or moved.
116116

117-
In Symfony2, a new class - ``UniversalClassLoader`` - handles this process.
117+
In Symfony2, a tool named `Composer`_ handles this process.
118118
The idea behind the autoloader is simple: the name of your class (including
119119
the namespace) must match up with the path to the file containing that class.
120120
Take 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.
136136
Specifically, the namespace, ``Sensio\Bundle\FrameworkExtraBundle``, spells out
137137
the 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

152141
If 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
160149
As 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
162151
example, 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

166159
If you look at the ``HelloController`` from the Symfony2 Standard Edition you
167160
can 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
312301
the chapter titled ":doc:`/book/service_container`".
313302

314303
.. _`Symfony2 Standard`: https://github.com/symfony/symfony-standard
304+
.. _`Composer`: http://getcomposer.org

0 commit comments

Comments
 (0)