You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
to return the correct DI alias. The DI alias is the name used to refer to the
bundle in the container (e.g. in the ``app/config/config.yml``file). By
methodto return the correct DI alias. The DI alias is the name used to refer to
thebundle in the container (e.g. in the ``config/packages/``files). By
default, this is done by removing the ``Extension`` suffix and converting the
class name to underscores (e.g. ``AcmeHelloExtension``'s DI alias is
``acme_hello``).
Expand All
@@ -86,11 +83,10 @@ container.
In the ``load()`` method, you can use PHP code to register service definitions,
but it is more common if you put these definitions in a configuration file
(using the Yaml, XML or PHP format). Luckily, you can use the file loaders in
the extension!
(using the YAML, XML or PHP format).
For instance, assume you have a file called ``services.xml`` in the
``Resources/config`` directory of your bundle, your ``load()`` method looks like::
``Resources/config/`` directory of your bundle, your ``load()`` method looks like::
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
Expand All
@@ -105,39 +101,22 @@ For instance, assume you have a file called ``services.xml`` in the
$loader->load('services.xml');
}
Other available loaders are the ``YamlFileLoader``, ``PhpFileLoader`` and
``IniFileLoader``.
.. note::
The ``IniFileLoader`` can only be used to load parameters and it can only
load them as strings.
.. caution::
If you removed the default file with service definitions (i.e.
``config/services.yaml``), make sure to also remove it from the
``imports`` key in ``app/config/config.yml``.
The other available loaders are ``YamlFileLoader`` and ``PhpFileLoader``.
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:`/bundles/configuration`" article.
particular bundle (e.g. the configuration in ``config/packages/<bundle_alias>.yaml``).
Toread more about it, see the ":doc:`/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()`` and ``addAnnotatedClassesToCompile()`` methods (both
work in the same way, but the second one is for classes that contain PHP
annotations). Define the classes to compile as an array of their fully qualified
class names::
Bundles can hint Symfony about which of their classes contain annotations so
they are compiled when generating the application cache to improve the overall
performance. Define the list of annotated classes to compile in the
``addAnnotatedClassesToCompile()`` method::
use App\Manager\UserManager;
use App\Utils\Slugger;
Expand All
@@ -147,16 +126,12 @@ class names::
{
// ...
// this method can't compile classes that contain PHP annotations
$this->addClassesToCompile(array(
UserManager::class,
Slugger::class,
// ...
));
// add here only classes that contain PHP annotations
$this->addAnnotatedClassesToCompile(array(
// you can define the fully qualified class names...
'App\\Controller\\DefaultController',
// ... but glob patterns are also supported:
'**Bundle\\Controller\\',
// ...
));
}
Expand All
@@ -166,24 +141,6 @@ class names::
If some class extends from other classes, all its parents are automatically
included in the list of classes to compile.
The classes to compile can also be added using file path patterns::
// ...
public function load(array $configs, ContainerBuilder $container)
{
// ...
$this->addClassesToCompile(array(
'**Bundle\\Manager\\',
// ...
));
$this->addAnnotatedClassesToCompile(array(
'**Bundle\\Controller\\',
// ...
));
}
Patterns are transformed into the actual class namespaces using the classmap
generated by Composer. Therefore, before using these patterns, you must generate
the full classmap executing the ``dump-autoload`` command of Composer.
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.