@@ -133,31 +133,66 @@ Symfony creates a big ``classes.php`` file in the cache directory to aggregate
133
133
the contents of the PHP classes that are used in every request. This reduces the
134
134
I/O operations and increases the application performance.
135
135
136
+ .. versionadded :: 3.2
137
+ The ``addAnnotatedClassesToCompile() `` method was added in Symfony 3.2.
138
+
136
139
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::
139
144
140
145
// ...
141
146
public function load(array $configs, ContainerBuilder $container)
142
147
{
143
148
// ...
144
149
150
+ // this method can't compile classes that contain PHP annotations
145
151
$this->addClassesToCompile(array(
146
152
'AppBundle\\Manager\\UserManager',
147
153
'AppBundle\\Utils\\Slugger',
148
154
// ...
149
155
));
156
+
157
+ // add here only classes that contain PHP annotations
158
+ $this->addAnnotatedClassesToCompile(array(
159
+ 'AppBundle\\Controller\\DefaultController',
160
+ // ...
161
+ ));
150
162
}
151
163
152
164
.. note ::
153
165
154
166
If some class extends from other classes, all its parents are automatically
155
167
included in the list of classes to compile.
156
168
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 ::
158
195
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