From 13284cbe8662b0b44fc3fbaa73fe214051352145 Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Sun, 20 Jan 2013 20:09:46 +0000 Subject: [PATCH 1/2] Adding notes about Extension registration to the DI component --- .../dependency_injection/compilation.rst | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/components/dependency_injection/compilation.rst b/components/dependency_injection/compilation.rst index c136a4149ba..70ee0644001 100644 --- a/components/dependency_injection/compilation.rst +++ b/components/dependency_injection/compilation.rst @@ -119,6 +119,12 @@ processed when the container is compiled at which point the Extensions are loade // ... $container->compile(); +.. note:: + + When loading a config file that uses an extension alias as a key, the + extension must already have been registered with the container builder + or an exception will be thrown. + The values from those sections of the config files are passed into the first argument of the ``load`` method of the extension:: @@ -239,6 +245,27 @@ but also load a secondary one only if a certain parameter is set:: } } +.. note:: + + Just registering an extension with the container is not enough to get + it included in the processed extensions when the container is compiled. + Loading config which uses the extension's alias as a key as in the above + examples will ensure it is loaded. The container builder can also be + told to load it with its + :method:`Symfony\\Component\\DependencyInjection\\ContainerBuilder::loadFromExtension` + method:: + + use Symfony\Component\DependencyInjection\ContainerBuilder; + use Symfony\Component\Config\FileLocator; + use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + + $container = new ContainerBuilder(); + $extension = new AcmeDemoExtension; + $container->registerExtension($extension); + $container->loadFromExtension($extension->getAlias()); + $container->compile(); + + .. note:: If you need to manipulate the configuration loaded by an extension then From 6785e7c8d25bcea660e1b9b355e25faf392d60ed Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Sun, 20 Jan 2013 20:38:15 +0000 Subject: [PATCH 2/2] Removing unused use statements from code sample --- components/dependency_injection/compilation.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/dependency_injection/compilation.rst b/components/dependency_injection/compilation.rst index 70ee0644001..0da43931f8c 100644 --- a/components/dependency_injection/compilation.rst +++ b/components/dependency_injection/compilation.rst @@ -256,11 +256,9 @@ but also load a secondary one only if a certain parameter is set:: method:: use Symfony\Component\DependencyInjection\ContainerBuilder; - use Symfony\Component\Config\FileLocator; - use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; $container = new ContainerBuilder(); - $extension = new AcmeDemoExtension; + $extension = new AcmeDemoExtension(); $container->registerExtension($extension); $container->loadFromExtension($extension->getAlias()); $container->compile();