-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Determine templating.engine.php scope as late as possible #11961
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
lyrixx
commented
Sep 19, 2014
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #11653 |
License | MIT |
Doc PR | - |
@@ -536,6 +537,7 @@ protected function createContainerFromFile($file, $data = array()) | ||
{ | ||
$container = $this->createContainer($data); | ||
$container->registerExtension(new FrameworkExtension()); | ||
$container->addCompilerPass(new TemplatingAssetHelperPass()); |
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.
If I had to make tests green without changing them, I had to add this one. So I don't know what should I do:
- Remove
$this->assertEquals('request', $container->getDefinition('templating.helper.assets')->getScope(), '->registerTemplatingConfiguration() sets request scope on assets helper if one or more packages are request-scoped');
line from this test suite and fully unit testTemplatingAssetHelperPass
- or keep it like now.
- mix both solution
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.
I added some unit tests to the TemplatingAssetHelperPass
. But my previous question stays open ;)
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.
I would vote for the first option. It is not the job of the FrameworkExtension anymore to set this scope
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.
done.
ea937be
to
e2bd6c1
Compare
return; | ||
} | ||
|
||
foreach ($assetsHelperDefinition->getArgument(1) as $arg) { |
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.
why not just $args[1]
?
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.
I forgot to update this part of the code ;)
b5fc3c0
to
f70d1cf
Compare
} | ||
|
||
foreach ($args[1] as $arg) { | ||
if ('request' === $this->getPackageScope($container, $arg)) { |
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.
this is a bit dangerous. If another compiler pass changes one of the arguments (for instance adding an anonymous service rather than creating a private service and referencing it), you will get a fatal error because of the typehint
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.
I'm not sure to know how it's possible. Does the DIC component allow that?
I can check for Reference
, but what kind of object / value should I check ?
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 anonymous service will be a Definition object set in the arguments directly. And yes it is allowed (it cannot be done in YAML config files though, but XML supports it, as well as PHP as you build the Definition directly)
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 ok. I never did that before, and I just try anonymous definition, and actually, a reference is created.
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.
I don't know what I'm doing, please double check ;)
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.
Nice,I just try $container->register('foo', 'stdClass')->addArgument(new Definition('stdClass'));
in a real project and it works. I never did that before ;)
5cfe93f
to
12e544a
Compare
private function getPackageScope(ContainerBuilder $container, $package) | ||
{ | ||
if ($package instanceof Reference) { | ||
return $container->getDefinition((string) $package)->getScope(); |
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 should use findDefinition
rather than getDefinition
to resolve aliases. Otherwise you will get an exception if the reference points to an alias rather than a definition
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.
done.
12e544a
to
159a4bf
Compare
👍 |
return; | ||
} | ||
|
||
foreach ($args[1] as $arg) { |
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.
Should we asserts that $args[1] is an array?
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.
I added a check, but it's a bit useless imho, because if it's not an array, the service will not be bootable, and will lead to a fatal error.
159a4bf
to
169dadd
Compare
Thank you @lyrixx. |
…e as late as possible (lyrixx) This PR was merged into the 2.6-dev branch. Discussion ---------- [FrameworkBundle] Determine templating.engine.php scope as late as possible | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11653 | License | MIT | Doc PR | - Commits ------- 169dadd [FrameworkBundle] Determine templating.engine.php scope as late as possible