Skip to content

Commit e2a67cd

Browse files
javiereguiluzxabbuh
authored andcommitted
Documented addAnnotatedClassesToCompile() and the use of class patterns
1 parent f0db5af commit e2a67cd

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

bundles/extension.rst

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,66 @@ Symfony creates a big ``classes.php`` file in the cache directory to aggregate
133133
the contents of the PHP classes that are used in every request. This reduces the
134134
I/O operations and increases the application performance.
135135

136+
.. versionadded:: 3.2
137+
The ``addAnnotatedClassesToCompile()`` method was added in Symfony 3.2.
138+
136139
Your bundles can also add their own classes into this file thanks to the
137-
``addClassesToCompile()`` method. Define the classes to compile as an array of
138-
their fully qualified class names::
140+
``addClassesToCompile()`` and ``addAnnotatedClassesToCompile()`` methods (both
141+
work in the same way, but the second one is for classes that contain PHP
142+
annotations). Define the classes to compile as an array of their fully qualified
143+
class names::
139144

140145
// ...
141146
public function load(array $configs, ContainerBuilder $container)
142147
{
143148
// ...
144149

150+
// this method can't compile classes that contain PHP annotations
145151
$this->addClassesToCompile(array(
146152
'AppBundle\\Manager\\UserManager',
147153
'AppBundle\\Utils\\Slugger',
148154
// ...
149155
));
156+
157+
// add here only classes that contain PHP annotations
158+
$this->addAnnotatedClassesToCompile(array(
159+
'AppBundle\\Controller\\DefaultController',
160+
// ...
161+
));
150162
}
151163

152164
.. note::
153165

154166
If some class extends from other classes, all its parents are automatically
155167
included in the list of classes to compile.
156168

157-
Beware that this technique **can't be used in some cases**:
169+
.. versionadded:: 3.2
170+
The option to add classes to compile using patterns was introduced in Symfony 3.2.
171+
172+
The classes to compile can also be added using file path patterns::
173+
174+
// ...
175+
public function load(array $configs, ContainerBuilder $container)
176+
{
177+
// ...
178+
179+
$this->addClassesToCompile(array(
180+
'**Bundle\\Manager\\',
181+
// ...
182+
));
183+
184+
$this->addAnnotatedClassesToCompile(array(
185+
'**Bundle\\Controller\\',
186+
// ...
187+
));
188+
}
189+
190+
Patterns are transformed into the actual class namespaces using the classmap
191+
generated by Composer. Therefore, before using these patterns, you must generate
192+
the full classmap executing the ``dump-autoload`` command of Composer.
193+
194+
.. caution::
158195

159-
* When classes contain annotations, such as controllers with ``@Route``
160-
annotations and entities with ``@ORM`` or ``@Assert`` annotations, because
161-
the file location retrieved from PHP reflection changes;
162-
* When classes use the ``__DIR__`` and ``__FILE__`` constants, because their
163-
values will change when loading these classes from the ``classes.php`` file.
196+
This technique can't be used when the classes to compile use the ``__DIR__``
197+
or ``__FILE__`` constants, because their values will change when loading
198+
these classes from the ``classes.php`` file.

0 commit comments

Comments
 (0)