Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Merged
merged 1 commit into from
Sep 22, 2014

Conversation

lyrixx
Copy link
Member

@lyrixx 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());
Copy link
Member Author

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 test TemplatingAssetHelperPass
  • or keep it like now.
  • mix both solution

Copy link
Member Author

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 ;)

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@lyrixx lyrixx force-pushed the asset-package-dic-scope-request branch from ea937be to e2bd6c1 Compare September 20, 2014 00:17
return;
}

foreach ($assetsHelperDefinition->getArgument(1) as $arg) {
Copy link
Member

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] ?

Copy link
Member Author

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 ;)

@lyrixx lyrixx force-pushed the asset-package-dic-scope-request branch 3 times, most recently from b5fc3c0 to f70d1cf Compare September 20, 2014 00:27
}

foreach ($args[1] as $arg) {
if ('request' === $this->getPackageScope($container, $arg)) {
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member Author

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 ;)

Copy link
Member Author

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 ;)

@lyrixx lyrixx force-pushed the asset-package-dic-scope-request branch 2 times, most recently from 5cfe93f to 12e544a Compare September 20, 2014 01:01
private function getPackageScope(ContainerBuilder $container, $package)
{
if ($package instanceof Reference) {
return $container->getDefinition((string) $package)->getScope();
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@lyrixx lyrixx force-pushed the asset-package-dic-scope-request branch from 12e544a to 159a4bf Compare September 20, 2014 18:33
@fabpot
Copy link
Member

fabpot commented Sep 21, 2014

👍

return;
}

foreach ($args[1] as $arg) {
Copy link
Member

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?

Copy link
Member Author

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.

@lyrixx lyrixx force-pushed the asset-package-dic-scope-request branch from 159a4bf to 169dadd Compare September 22, 2014 08:43
@fabpot
Copy link
Member

fabpot commented Sep 22, 2014

Thank you @lyrixx.

@fabpot fabpot merged commit 169dadd into symfony:master Sep 22, 2014
fabpot added a commit that referenced this pull request Sep 22, 2014
…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
@lyrixx lyrixx deleted the asset-package-dic-scope-request branch September 22, 2014 12:41
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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.