Skip to content

[TwigBundle] Added a RuntimeExtensionInterface to take advantage of autoconfigure #23037

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
Jul 12, 2017

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jun 2, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets - (asked by @nicolas-grekas)
License MIT
Doc PR -

Before:

#app/config/services.yml
services:
    _defaults:
        autoconfigure: true
  
    AppBundle\Twig\HelloExtension:
        tags: ['twig.runtime']

After:

#app/config/services.yml
services:
    _defaults:
        autoconfigure: true

#Yes, there are nothing anymore

@@ -150,6 +151,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->registerForAutoconfiguration(\Twig_LoaderInterface::class)->addTag('twig.loader');
$container->registerForAutoconfiguration(ExtensionInterface::class)->addTag('twig.extension');
$container->registerForAutoconfiguration(LoaderInterface::class)->addTag('twig.loader');
$container->registerForAutoconfiguration(RuntimeExtensionInterface::class)->addTag('twig.runtime');

if (\PHP_VERSION_ID < 70000) {

Choose a reason for hiding this comment

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

Still useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? (3.* Still supports php 5)

*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
interface RuntimeExtensionInterface
Copy link
Member

Choose a reason for hiding this comment

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

What about moving this to Twig itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is useless in twig, isn't ?

Copy link
Member

Choose a reason for hiding this comment

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

but having an interface in SF only will prevent non SF users from tagging their runtime on their side
+1 for Twig (1.x)

Copy link
Member Author

Choose a reason for hiding this comment

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

But it is useless to tag the runtime interface on their side. It is only useful in a symfony context.

What is the benefits of moving it to twig ?

Copy link
Member

@nicolas-grekas nicolas-grekas Jun 3, 2017

Choose a reason for hiding this comment

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

the benefit is that SF can leverage it (as you do here),
and others can also :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I do that?
Because for me it does not make sense to introduce an interface in twig.
It's just plain dead code. What would be the documentation for this Interface?

Copy link
Member

Choose a reason for hiding this comment

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

but then it means that your library providing a reusable extension can either decide to couple itself to Symfony, or cannot benefit from autowiring when using it with Symfony (and then, other frameworks supporting autowiring also need to add their own version of this interface).

So I'm in favor of adding the marker interface in Twig.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -12,6 +12,7 @@
namespace Symfony\Bundle\TwigBundle\DependencyInjection;

use Symfony\Bridge\Twig\Extension\WebLinkExtension;
use Symfony\Bundle\TwigBundle\RuntimeExtensionInterface;
Copy link
Member

Choose a reason for hiding this comment

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

to be replaced by the upcoming Twig interface (and this one removed)

@lyrixx
Copy link
Member Author

lyrixx commented Jul 11, 2017

PR updated.

@nicolas-grekas
Copy link
Member

Thank you @lyrixx.

@nicolas-grekas nicolas-grekas merged commit ba8763b into symfony:3.4 Jul 12, 2017
nicolas-grekas added a commit that referenced this pull request Jul 12, 2017
… advantage of autoconfigure (lyrixx)

This PR was merged into the 3.4 branch.

Discussion
----------

[TwigBundle] Added a RuntimeExtensionInterface to take advantage of autoconfigure

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | - (asked by @nicolas-grekas)
| License       | MIT
| Doc PR        | -

---

Before:

```yaml
#app/config/services.yml
services:
    _defaults:
        autoconfigure: true

    AppBundle\Twig\HelloExtension:
        tags: ['twig.runtime']
```

After:

```yaml
#app/config/services.yml
services:
    _defaults:
        autoconfigure: true

#Yes, there are nothing anymore
```

Commits
-------

ba8763b [TwigBundle] Added a RuntimeExtensionInterface to take advantage of autoconfigure
@lyrixx lyrixx deleted the twig-ext-alias branch July 12, 2017 08:31
This was referenced Oct 18, 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.

6 participants