Skip to content

[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

Merged
merged 1 commit into from
Sep 26, 2017
Merged

[DI][DX] Throw exception on some ContainerBuilder methods used from extensions #24295

merged 1 commit into from
Sep 26, 2017

Conversation

ogizanagi
Copy link
Contributor

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

@ogizanagi ogizanagi added DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature labels Sep 23, 2017
@linaori
Copy link
Contributor

linaori commented Sep 23, 2017

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.');
Copy link
Contributor

@sstok sstok Sep 24, 2017

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));
Copy link
Member

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.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

with "wording" comments

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Sep 24, 2017
@ogizanagi
Copy link
Contributor Author

ogizanagi commented Sep 24, 2017

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 Bundle::build is not pretty accurate to me :/

*/
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.');
Copy link
Member

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.');
Copy link
Member

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__));
Copy link
Member

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.

@ogizanagi
Copy link
Contributor Author

Much better! Thanks @nicolas-grekas

@ogizanagi ogizanagi merged commit 88549ff into symfony:3.4 Sep 26, 2017
ogizanagi added a commit that referenced this pull request Sep 26, 2017
…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
@ogizanagi ogizanagi deleted the di/throw_add_pass_from_ext branch September 26, 2017 05:55
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants