Skip to content

Commit 13284cb

Browse files
Adding notes about Extension registration to the DI component
1 parent 0b0164f commit 13284cb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

components/dependency_injection/compilation.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ processed when the container is compiled at which point the Extensions are loade
119119
// ...
120120
$container->compile();
121121

122+
.. note::
123+
124+
When loading a config file that uses an extension alias as a key, the
125+
extension must already have been registered with the container builder
126+
or an exception will be thrown.
127+
122128
The values from those sections of the config files are passed into the first
123129
argument of the ``load`` method of the extension::
124130

@@ -239,6 +245,27 @@ but also load a secondary one only if a certain parameter is set::
239245
}
240246
}
241247

248+
.. note::
249+
250+
Just registering an extension with the container is not enough to get
251+
it included in the processed extensions when the container is compiled.
252+
Loading config which uses the extension's alias as a key as in the above
253+
examples will ensure it is loaded. The container builder can also be
254+
told to load it with its
255+
:method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::loadFromExtension`
256+
method::
257+
258+
use Symfony\Component\DependencyInjection\ContainerBuilder;
259+
use Symfony\Component\Config\FileLocator;
260+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
261+
262+
$container = new ContainerBuilder();
263+
$extension = new AcmeDemoExtension;
264+
$container->registerExtension($extension);
265+
$container->loadFromExtension($extension->getAlias());
266+
$container->compile();
267+
268+
242269
.. note::
243270

244271
If you need to manipulate the configuration loaded by an extension then

0 commit comments

Comments
 (0)