@@ -119,7 +119,7 @@ were added or moved.
119
119
In Symfony2, a tool named `Composer `_ handles this process.
120
120
The idea behind the autoloader is simple: the name of your class (including
121
121
the namespace) must match up with the path to the file containing that class.
122
- Take the `` FrameworkExtraBundle `` from the Symfony2 Standard Edition as an
122
+ Take the FrameworkExtraBundle from the Symfony2 Standard Edition as an
123
123
example::
124
124
125
125
namespace Sensio\Bundle\FrameworkExtraBundle;
@@ -134,26 +134,30 @@ example::
134
134
135
135
The file itself lives at
136
136
``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/SensioFrameworkExtraBundle.php ``.
137
- As you can see, the location of the file follows the namespace of the class.
138
- Specifically, the namespace, ``Sensio\Bundle\FrameworkExtraBundle ``, spells out
139
- the directory that the file should live in
137
+ As you can see, the second part of the path follows the namespace of the
138
+ class. The first part is equal to the package name of the SensioFrameworkExtraBundle.
139
+
140
+ The namespace, ``Sensio\Bundle\FrameworkExtraBundle ``, and package name,
141
+ ``sensio/framework-extra-bundle ``, spells out the directory that the file
142
+ should live in
140
143
(``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/ ``).
141
- Composer can then look for the file at this specific place and load it very fast.
144
+ Composer can then look for the file at this specific place and load it very
145
+ fast.
142
146
143
147
If the file did *not * live at this exact location, you'd receive a
144
148
``Class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" does not exist. ``
145
- error. In Symfony2, a "class does not exist" means that the suspect class
146
- namespace and physical location do not match. Basically, Symfony2 is looking
149
+ error. In Symfony2, a "class does not exist" error means that the namespace of
150
+ the class and physical location do not match. Basically, Symfony2 is looking
147
151
in one exact location for that class, but that location doesn't exist (or
148
152
contains a different class). In order for a class to be autoloaded, you
149
153
**never need to clear your cache ** in Symfony2.
150
154
151
155
As mentioned before, for the autoloader to work, it needs to know that the
152
- ``Sensio `` namespace lives in the ``vendor/bundles `` directory and that, for
153
- example, the ``Doctrine `` namespace lives in the `` vendor/doctrine/orm/lib/ ``
154
- directory. This mapping is entirely controlled by Composer. Each
155
- third-party library you load through composer has their settings defined
156
- and Composer takes care of everything for you.
156
+ ``Sensio `` namespace lives in the ``vendor/sensio/framework-extra-bundle ``
157
+ directory and that, for example, the ``Doctrine `` namespace lives in the
158
+ `` vendor/doctrine/orm/lib/ `` directory. This mapping is entirely controlled by
159
+ Composer. Each third-party library you load through Composer has its
160
+ settings defined and Composer takes care of everything for you.
157
161
158
162
For this to work, all third-party libraries used by your project must be
159
163
defined in the ``composer.json `` file.
@@ -170,6 +174,11 @@ from specific directories without defining a dependency:
170
174
" psr-0 " : { "": "src/" }
171
175
}
172
176
177
+ This means that if a class is not found in the ``vendor `` directory, Composer
178
+ will search in the ``src `` directory before throwing a "class does not exist"
179
+ exception. Read more about configuring the Composer Autoloader in
180
+ `the Composer documentation `_
181
+
173
182
Using the Console
174
183
-----------------
175
184
@@ -357,3 +366,4 @@ the chapter titled ":doc:`/book/service_container`".
357
366
358
367
.. _`Composer` : http://getcomposer.org
359
368
.. _`Symfony2 Standard Edition` : https://github.com/symfony/symfony-standard
369
+ .. _`the Composer documentation` : http://getcomposer.org/doc/04-schema.md#autoload
0 commit comments