-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.