Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TwigBundle] Added priority to twig extensions #24777

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

Closed
wants to merge 12 commits into from
Closed

[TwigBundle] Added priority to twig extensions #24777

wants to merge 12 commits into from

Conversation

Brunty
Copy link
Contributor

@Brunty Brunty commented Oct 31, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR Don't merge before the docs

Added priority to twig extensions in the TwigEnvironmentPass to control the order in which they're registered, similar to the TwigLoaderPass

Though, unsure on what priority to use as a default, and will PR docs when finalised.

foreach ($container->findTaggedServiceIds('twig.extension', true) as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$prioritizedLoaders[$priority][] = $id;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be replaced by using the PriorityTaggedServiceTrait?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iltar done :)

@fabpot
Copy link
Member

fabpot commented Nov 1, 2017

Can you explain the use case for having priorities on extensions? I do understand the need for loaders, but I fail to see why we would need them for extensions.

@Brunty
Copy link
Contributor Author

Brunty commented Nov 1, 2017

@fabpot I was recently working on something and needed to overload a filter - I was lucky in that where I was registering it, it was after the previous one being registered (so as per docs here: https://twig.symfony.com/doc/2.x/advanced.html#overloading) but figured that might not always be the case.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Nov 1, 2017
foreach ($container->findTaggedServiceIds('twig.extension', true) as $id => $attributes) {
$definition->addMethodCall('addExtension', array(new Reference($id)));
foreach ($this->findAndSortTaggedServices('twig.extension', $container) as $extension) {
$definition->addMethodCall('addExtension', array(new Reference($extension)));
Copy link
Member

Choose a reason for hiding this comment

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

$extension is already a reference so that this code could be simplified

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

needs a CHANGELOG entry i guess.

class TwigEnvironmentPassTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
Copy link
Contributor

@ro0NL ro0NL Nov 18, 2017

Choose a reason for hiding this comment

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

for clarity i prefer /** @var Type */ thus inline. But not a blocker :) and im not sure we do that elsewhere anyway.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK, we don't do much "inline" on properties.

@Brunty
Copy link
Contributor Author

Brunty commented Nov 18, 2017

@ro0NL will add a changelog entry now, what version should it go under?

@ro0NL
Copy link
Contributor

ro0NL commented Nov 18, 2017

4.0.0 but there's a 4.4.0 entry already, i think it's a typo :)

@Brunty
Copy link
Contributor Author

Brunty commented Nov 18, 2017

@ro0NL I'll add a 4.0.0 section, want me to correct the 4.4.0 one to 4.0.0?

@ro0NL
Copy link
Contributor

ro0NL commented Nov 18, 2017

think so. affects master only anyway.

@Brunty
Copy link
Contributor Author

Brunty commented Nov 18, 2017

@ro0NL - added changelog entry for you

-----

* removed `ContainerAwareRuntimeLoader`
* added priority to twig extensions
Copy link
Member

Choose a reason for hiding this comment

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

should be added in a new entry for 4.1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas done :)

4.4.0
4.1.0
-----
* added priority to twig extensions
Copy link
Member

Choose a reason for hiding this comment

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

Twig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed


protected function setUp()
{
$this->builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'setAlias', 'getDefinition'))->getMock();
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 not mock the ContainerBuilder class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

please do so :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh done :)

@@ -1,6 +1,10 @@
CHANGELOG
=========

4.1.0
-----
* added priority to Twig extensions
Copy link
Member

Choose a reason for hiding this comment

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

missing blank line before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added :)

*/
private $pass;

protected function setUp()
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this method IMHO, better remove it and the corresponding properties

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

@fabpot
Copy link
Member

fabpot commented Jan 17, 2018

Thank you @Brunty.

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.

7 participants