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
Conversation
@@ -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())); |
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.
does it hurt to keep this one so that people not using MergeExtensionConfigurationPass don't experience a breakage?
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.
It hurts SF by default :) in terms of registering a duplicate resource. Imo. it just dont belong here..
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.
breakage >>> duplicate resource :)
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.
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.
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.
Note that duplicate resources are not actually stored in the cache.
public function getResources()
{
return array_unique($this->resources);
}
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.
Fair enough. I still think the "change" is considerable, but we can keep things as is here. Doing things twice by default.
Updated to 2.7, reverted base However, we could update built in bundles to bypass That should improve something. |
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); |
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.
Now, we have two resources being registered when getConfiguration()
is used.
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.
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.
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.
Hm yeah, thinking about this again two resources shouldn't really hurt.
Test added. What about core bundles with different implementations regarding Then again, maye this should work vice-versa, updating bundles to consistently track resources from I think moving the responsibility away from Im not sure. |
👍 Status: Reviewed |
👍 for keeping thing as is from here. |
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.
👍
Thank you @ro0NL. |
…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
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.