mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
2fd05fdd05
This PR was merged into the 1.x branch.
Discussion
----------
Add a simple Twig_RuntimeLoaderInterface implementation
Next to https://github.com/symfony/symfony/pull/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