Skip to content

Commit

Permalink
Added the explanation about addClassesToCompile() method
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz authored and wouterj committed May 21, 2016
1 parent fe11cd8 commit c5664a1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cookbook/bundles/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,39 @@ Using Configuration to Change the Services
The Extension is also the class that handles the configuration for that
particular bundle (e.g. the configuration in ``app/config/config.yml``). To
read more about it, see the ":doc:`/cookbook/bundles/configuration`" article.

Adding Classes to Compile
-------------------------

Symfony creates a big ``classes.php`` file in the cache directory to aggregate
the contents of the PHP classes that are used in every request. This reduces the
I/O operations and increases the application performance.

Your bundles can also add their own classes into this file thanks to the
``addClassesToCompile()`` method. Define the classes to compile as an array of
their fully qualified class names::

// ...
public function load(array $configs, ContainerBuilder $container)
{
// ...

$this->addClassesToCompile(array(
'AppBundle\\Manager\\UserManager',
'AppBundle\\Utils\\Slugger',
// ...
));
}

.. note::

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

Beware that this technique **can't be used in some cases**:

* When classes contain annotations, such as controllers with ``@Route``
annotations and entities with ``@ORM`` or ``@Assert`` annotations, because
the file location retrieved from PHP reflection changes;
* When classes use the ``__DIR__`` and ``__FILE__`` constants, because their
values will change when loading these classes from the ``classes.php`` file.

0 comments on commit c5664a1

Please sign in to comment.