8000 feature #6405 Added the explanation about addClassesToCompile() metho… · symfony/symfony-docs@41716df · GitHub
[go: up one dir, main page]

Skip to content

Commit 41716df

Browse files
committed
feature #6405 Added the explanation about addClassesToCompile() method (javiereguiluz)
This PR was squashed before being merged into the 2.3 branch (closes #6405). Discussion ---------- Added the explanation about addClassesToCompile() method This fixes #4492. Commits ------- c5664a1 Added the explanation about addClassesToCompile() method
2 parents 8f46cb8 + c5664a1 commit 41716df

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

cookbook/bundles/extension.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,39 @@ Using Configuration to Change the Services
125125
The Extension is also the class that handles the configuration for that
126126
particular bundle (e.g. the configuration in ``app/config/config.yml``). To
127127
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

Comments
 (0)
0