-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 3 commits
e300ed1
b08ddc7
3b1dd7e
be5d961
7dff210
5c0f0ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,3 +125,42 @@ 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 fully qualified class | ||
names:: | ||
|
||
// ... | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
// ... | ||
|
||
$this->addClassesToCompile(array( | ||
'AppBundle\\Manager\\UserManager', | ||
'AppBundle\\Service\\Slugger', | ||
// ... | ||
)); | ||
} | ||
|
||
.. note:: | ||
|
||
If some class extends from other classes, all its parents are included | ||
automatically in the list of classes to compile. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "[...] are automatically included [...]" |
||
|
||
After adding to compile all the classes commonly used by your bundle, you can | ||
expect a minor performance improvement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 when: | ||
|
||
* Classes contain annotations, such as controllers with ``@Route`` annotations | ||
and entities with ``@ORM`` or ``@Assert`` annotations; | ||
* Classes use the ``__DIR__`` and ``__FILE__`` constants, because their values | ||
will change when loading these classes from the ``classes.php`` file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally would find it interesting to know why it doesn't work for annotations. One of the reasons is the file location retrieved from reflection. Is this something you could add to the documentation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just added your proposal. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using the
class
constant here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's 2.3, let's not do that. We should however use a single backslash instead of double ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I would not advice to use a
Service
namespace, causes confusion for users.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say let's not do that because we're still targeting PHP 5.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj I agree about the namespace. Changed!