8000 Added the explanation about addClassesToCompile() method by javiereguiluz · Pull Request #6405 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Added the explanation about addClassesToCompile() method #6405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added the explanation about addClassesToCompile() method
  • Loading branch information
javiereguiluz committed Mar 29, 2016
commit e300ed1ce06107659b74a38f8612541aca1f2dde
24 changes: 24 additions & 0 deletions cookbook/bundles/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,27 @@ 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
-------------------------

In order to make applications run as fast as possible on production environment,
Symfony creates a big ``classes.php`` file in the cache directory. This file
aggregates the contents of the PHP classes that are used in every request,
reducing the I/O operations related to those classes.

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

$this->addClassesToCompile(array(
'Appbundle\\Manager\\UserManager',
'Appbundle\\Service\\Slugger',
// ...
));

If you add to compile all the classes commonly used by your bundle, you can
expect a minor performance improvement.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that this paragraph doesn't add any value and can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we explain how to do something ... but not why it's useful. But I'm going to reword it.

Copy link
Member
@wouterj wouterj May 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the first sentence of the section already explains that we do this to improve performance.


The main drawback of this technique is that it doesn't work for classes which
contains annotations, such as controllers with ``@Route`` annotations and
entities with ``@ORM`` or ``@Assert`` annotations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes containing usages of __DIR__ and __FILE__ cannot be added either (as loading them from classes.php would change these paths).

You should also ad a note saying that adding a class will automatically add any parent class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent warnings! Thank you. I've added them and reworded the rest a bit.

0