Skip to content

Commit 49c4ecf

Browse files
committed
Merge pull request #2161 from richardmiller/adding_di_note
Adding notes about Extension registration to the DI component
2 parents a928fa3 + 6785e7c commit 49c4ecf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

components/dependency_injection/compilation.rst

+25
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ processed when the container is compiled at which point the Extensions are loade
120120
// ...
121121
$container->compile();
122122

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

@@ -240,6 +246,25 @@ but also load a secondary one only if a certain parameter is set::
240246
}
241247
}
242248

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

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

0 commit comments

Comments
 (0)