8000 [TwigBridge] Add a runtime loader to the twig bridge to ease upgrading to 3.2+ by chalasr · Pull Request #21023 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] Add a runtime loader to the twig bridge to ease upgrading to 3.2+ #21023

8000 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

Conversation

chalasr
Copy link
Member
@chalasr chalasr commented Dec 22, 2016
Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes/no
Fixed tickets n/a
License MIT
Doc PR todo

This is related to the BC break reported in #21008 which has been introduced in #20093.

I think the BC break is acceptable since it is about bootstraping the form component with the twig bridge only, outside of the fullstack.
What I propose here is to ease upgrading by adding a simple runtime loader to the bridge, useful only when using the twig-bridge standalone.

So the upgrade would be as simple as:

use Symfony\Bridge\Twig\TwigRuntimeLoader;

$twig = new Twig_Environment(...);
$formEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
- $twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfManager)));
+ $twig->addExtension(new FormExtension());
+ $twig->addRuntimeLoader(new TwigRuntimeLoader(array(TwigRenderer::class => new TwigRenderer($formEngine, $csrfManager)));

Instead of having to write this runtime loader yourself. UPGRADE files and documentation should be updated accordingly (with or without this PR).
Please see #21008 for details and an exemple of how this could be applied.

@chalasr chalasr changed the title Add a runtime loader to the twig bridge to ease upgrading to 3.2 [TwigBridge] Add a runtime loader to the twig bridge to ease upgrading to 3.2+ Dec 22, 2016
@chalasr chalasr force-pushed the twig-bridge/simple-runtime-loader branch from 358e45e to 7dc473c Compare December 22, 2016 13:23
@stof
Copy link
Member
stof commented Dec 22, 2016

As this class has nothing specific to Symfony, I suggest putting it in Twig itself

@chalasr
Copy link
Member Author
chalasr commented Dec 22, 2016

See twigphp/Twig#2311

@chalasr chalasr closed this Dec 22, 2016
@chalasr chalasr deleted the twig-bridge/simple-runtime-loader branch December 22, 2016 15:34
fabpot added a commit to twigphp/Twig that referenced this pull request Dec 23, 2016
… (chalasr)

This PR was merged into the 1.x branch.

Discussion
----------

Add a simple Twig_RuntimeLoaderInterface implementation

Next to symfony/symfony#21023

This is related to the BC break reported in symfony/symfony#21008 which has been introduced in symfony/symfony#20093 when decoupling extensions from definitions.

What I propose here is to ease the upgrade to symfony 3.2+ by adding a simple `Twig_RuntimeLoaderInterface` implementation here, useful only when using the twig-bridge outside of the symfony fullstack framework (with the Form component for instance).

Upgrading would be as simple as:

```diff
$twig = new Twig_Environment(...);
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
- $twig->addExtension(new FormExtension(new TwigRenderer($rendererEngine, $csrfTokenManager)));
+ $twig->addExtension(new FormExtension());
+ $twig->addRuntimeLoader(new Twig_RuntimeLoader(array(TwigRenderer::class => new TwigRenderer($rendererEngine, $csrfTokenManager)));
```

Instead of having to write this runtime loader yourself.
Please see symfony/symfony#21008 for details and a concrete example of how this could help.

Commits
-------

91c8d59 Add a Twig_FactoryRuntimeLoader
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.

3 participants
0