-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI][DX] Throw exception on some ContainerBuilder methods used from extensions #24295
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
Conversation
ogizanagi
commented
Sep 23, 2017
Q | A |
---|---|
Branch? | 3.4 |
Bug fix? | no |
New feature? | yes |
BC breaks? | no (unlikely, that would mean there already was an issue in userland code) |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #24282 |
License | MIT |
Doc PR | N/A |
Yes, this is what I was referring to! This would reduce the amount of confusion and wtfs when working with the container. |
*/ | ||
public function registerExtension(ExtensionInterface $extension) | ||
{ | ||
throw new LogicException('You cannot register a extension from another extension.'); |
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.
an extension
*/ | ||
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/) | ||
{ | ||
throw new LogicException(sprintf('You cannot add compiler passes to the container builder from an extension. Add it from the main container builder (from a bundle %s::build() method for instance).', Bundle::class)); |
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.
You cannot add compiler passes to the container builder from an extension. Add it from your bundle's "build()" method instead.
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.
with "wording" comments
Updated. But I was referring to the "main container builder" for those using the DI component standalone (#24282 (comment)), without HttpKernel (so no bundle). Not sure how we could turn this better, but only mentioning |
*/ | ||
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, int $priority = 0*/) | ||
{ | ||
throw new LogicException('You cannot add compiler passes to the container builder from an extension. Add it from your bundle\'s "build()" method instead.'); |
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.
so, would this be better?
You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.
*/ | ||
public function registerExtension(ExtensionInterface $extension) | ||
{ | ||
throw new LogicException('You cannot register an extension from another extension.'); |
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.
You cannot register extension "%s" from "%s". Extensions must be registered before the container is compiled.
*/ | ||
public function compile($resolveEnvPlaceholders = false) | ||
{ | ||
throw new LogicException(sprintf('Cannot compile a %s instance.', __CLASS__)); |
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.
Cannot compile the container in extension "%s".
(no need to ref __CLASS__
, that'd be confusing I think.
Much better! Thanks @nicolas-grekas |
…ods used from extensions (ogizanagi) This PR was merged into the 3.4 branch. Discussion ---------- [DI][DX] Throw exception on some ContainerBuilder methods used from extensions | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes <!-- don't forget updating src/**/CHANGELOG.md files --> | BC breaks? | no (unlikely, that would mean there already was an issue in userland code) | Deprecations? | no <!-- don't forget updating UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #24282 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A Commits ------- 88549ff [DI][DX] Throw exception on some ContainerBuilder methods used from extensions