Commit 0115e23e authored by Fabien Potencier's avatar Fabien Potencier

bug #1431 Move setting $app['twig.app_variable'] after 'Symfony\Bridge\Twig' check (tiemevanveen)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Move setting $app['twig.app_variable'] after 'Symfony\Bridge\Twig' check

Currently `TwigServiceProvider ` sets `$app['twig.app_variable']` to be function that has a dependency on classes that are not required by Silex. This will fail if the user then calls that function. This happens for example when the [silex-pimple-dumper](https://github.com/Sorien/silex-pimple-dumper) maps over the app and tries to dump it's content.

This PR fixes that by moving this in the `class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')` check.

I've also added comment because at first it wasn't clear for me that this check for the `RoutingExtension` was the check for the whole Twig bridge. Please feel free to rebase and remove it it you don't like it or I misinterpreted it.

Keep up the good work! 👍

Commits
-------

b97f5a89 Move setting $app['twig.app_variable'] after 'Symfony\Bridge\Twig' check
parents 94f4855b b97f5a89
...@@ -39,19 +39,6 @@ class TwigServiceProvider implements ServiceProviderInterface ...@@ -39,19 +39,6 @@ class TwigServiceProvider implements ServiceProviderInterface
$app['twig.path'] = array(); $app['twig.path'] = array();
$app['twig.templates'] = array(); $app['twig.templates'] = array();
$app['twig.app_variable'] = function ($app) {
$var = new AppVariable();
if (isset($app['security.token_storage'])) {
$var->setTokenStorage($app['security.token_storage']);
}
if (isset($app['request_stack'])) {
$var->setRequestStack($app['request_stack']);
}
$var->setDebug($app['debug']);
return $var;
};
$app['twig'] = function ($app) { $app['twig'] = function ($app) {
$app['twig.options'] = array_replace( $app['twig.options'] = array_replace(
array( array(
...@@ -71,6 +58,19 @@ class TwigServiceProvider implements ServiceProviderInterface ...@@ -71,6 +58,19 @@ class TwigServiceProvider implements ServiceProviderInterface
} }
if (class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')) { if (class_exists('Symfony\Bridge\Twig\Extension\RoutingExtension')) {
$app['twig.app_variable'] = function ($app) {
$var = new AppVariable();
if (isset($app['security.token_storage'])) {
$var->setTokenStorage($app['security.token_storage']);
}
if (isset($app['request_stack'])) {
$var->setRequestStack($app['request_stack']);
}
$var->setDebug($app['debug']);
return $var;
};
$twig->addGlobal('global', $app['twig.app_variable']); $twig->addGlobal('global', $app['twig.app_variable']);
if (isset($app['request_stack'])) { if (isset($app['request_stack'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment