Skip to content
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

[DI] Auto register extension configuration classes as a resource #21057

Merged
merged 1 commit into from Feb 14, 2017
Merged

[DI] Auto register extension configuration classes as a resource #21057

merged 1 commit into from Feb 14, 2017

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Dec 26, 2016

Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

Auto-register an extension configuration class as a resource from a compiler pass; not implicitly by the base extension class.

Causing some extensions to register its configuration, whereas others dont (e.g. framework bundle).

Fixes consistent cache invalidation whenever a configuration definition changes.

@@ -82,13 +81,8 @@ public function getConfiguration(array $config, ContainerBuilder $container)
$namespace = $reflected->getNamespaceName();

$class = $namespace.'\\Configuration';
if (class_exists($class)) {
$r = new \ReflectionClass($class);
$container->addResource(new FileResource($r->getFileName()));
Copy link
Member

Choose a reason for hiding this comment

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

does it hurt to keep this one so that people not using MergeExtensionConfigurationPass don't experience a breakage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It hurts SF by default :) in terms of registering a duplicate resource. Imo. it just dont belong here..

Copy link
Member

Choose a reason for hiding this comment

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

breakage >>> duplicate resource :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understand.. but it's a breakage in behavior.. ie. it doesnt qualify a technical "BC Break".

I'd prefer master+changelog on those, rather then keeping quirky code. Trying to do all.

Copy link
Contributor

@sstok sstok Dec 28, 2016

Choose a reason for hiding this comment

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

Note that duplicate resources are not actually stored in the cache.

    public function getResources()
    {
        return array_unique($this->resources);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I still think the "change" is considerable, but we can keep things as is here. Doing things twice by default.

@ro0NL ro0NL changed the base branch from master to 2.7 December 28, 2016 10:12
@ro0NL
Copy link
Contributor Author

ro0NL commented Dec 28, 2016

Updated to 2.7, reverted base Extension.

However, we could update built in bundles to bypass Extension::getConfiguration right? Initializing the configuration class explicitly per extension (like the framework bundle already does).

That should improve something.

@nicolas-grekas
Copy link
Member

This should be considered as a bug, isn't it? What about adding a test case?

@@ -47,6 +48,9 @@ public function process(ContainerBuilder $container)
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($extension);
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
$tmpContainer->addObjectResource($configuration);
Copy link
Member

Choose a reason for hiding this comment

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

Now, we have two resources being registered when getConfiguration() is used.

Copy link
Contributor Author

@ro0NL ro0NL Dec 29, 2016

Choose a reason for hiding this comment

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

Correct :) see #21057 (comment)

I first targeted master, doing it only here (with in mind we do a changelog on behavioral change).

However now we target 2.7, in order to fix the behavior in lower branches. Indeed giving multiple resources by default. But's not really a big a deal, only weird looking at it :)

I still think we need to do

Initializing the configuration class explicitly per extension

In core.

Copy link
Member

Choose a reason for hiding this comment

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

Hm yeah, thinking about this again two resources shouldn't really hurt.

@ro0NL
Copy link
Contributor Author

ro0NL commented Dec 29, 2016

Test added.

What about core bundles with different implementations regarding getConfiguration?

Then again, maye this should work vice-versa, updating bundles to consistently track resources from getConfiguration vs. keeping it as is.

I think moving the responsibility away from getConfiguration makes sense.

Im not sure.

@xabbuh xabbuh added the Bug label Dec 29, 2016
@xabbuh
Copy link
Member

xabbuh commented Dec 29, 2016

👍

Status: Reviewed

@ro0NL
Copy link
Contributor Author

ro0NL commented Dec 29, 2016

👍 for keeping thing as is from here.

@xabbuh xabbuh added this to the 2.7 milestone Dec 29, 2016
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.

👍

@fabpot
Copy link
Member

fabpot commented Feb 14, 2017

Thank you @ro0NL.

@fabpot fabpot merged commit 142416b into symfony:2.7 Feb 14, 2017
fabpot added a commit that referenced this pull request Feb 14, 2017
…source (ro0NL)

This PR was merged into the 2.7 branch.

Discussion
----------

[DI] Auto register extension configuration classes as a resource

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

Auto-register an extension configuration class as a resource from a compiler pass; not implicitly by the base extension class.

Causing some extensions to register its configuration, whereas others dont (e.g. framework bundle).

Fixes consistent cache invalidation whenever a configuration definition changes.

Commits
-------

142416b [DI] Auto register extension configuration classes as a resource
@ro0NL ro0NL deleted the di/auto-register-resource branch February 14, 2017 19:12
@fabpot fabpot mentioned this pull request Feb 17, 2017
This was referenced Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants