Skip to content

Adding notes about Extension registration to the DI component #2161

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

Merged
merged 2 commits into from
Jan 20, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/dependency_injection/compilation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the first use statement is used, it is better to remove the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I've removed the other two.


$container = new ContainerBuilder();
$extension = new AcmeDemoExtension;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be new AcmeDemoExtension();?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly can be and is then consistent with the line above. Out of interest is there something about this in the CS standard regarding this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found it yet. We should maybe add this to the symfony CS as it is generally used in the core framework.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it is written in the doc, but it is applied in the code

$container->registerExtension($extension);
$container->loadFromExtension($extension->getAlias());
$container->compile();


.. note::

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