@@ -125,3 +125,39 @@ Using Configuration to Change the Services
125
125
The Extension is also the class that handles the configuration for that
126
126
particular bundle (e.g. the configuration in ``app/config/config.yml ``). To
127
127
read more about it, see the ":doc: `/cookbook/bundles/configuration `" article.
128
+
129
+ Adding Classes to Compile
130
+ -------------------------
131
+
132
+ Symfony creates a big ``classes.php `` file in the cache directory to aggregate
133
+ the contents of the PHP classes that are used in every request. This reduces the
134
+ I/O operations and increases the application performance.
135
+
136
+ 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::
139
+
140
+ // ...
141
+ public function load(array $configs, ContainerBuilder $container)
142
+ {
143
+ // ...
144
+
145
+ $this->addClassesToCompile(array(
146
+ 'AppBundle\\Manager\\UserManager',
147
+ 'AppBundle\\Utils\\Slugger',
148
+ // ...
149
+ ));
150
+ }
151
+
152
+ .. note ::
153
+
154
+ If some class extends from other classes, all its parents are automatically
155
+ included in the list of classes to compile.
156
+
157
+ Beware that this technique **can't be used in some cases **:
158
+
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.
0 commit comments