From 74936f2ba46d98a0130dc71efb838d018f4e8fc6 Mon Sep 17 00:00:00 2001 From: Alexandre Dupuy Date: Fri, 16 Sep 2016 12:13:07 +0200 Subject: [PATCH 1/2] twig: add DumpExtension if VarDumper and TwigBridge are available --- src/Templating/TwigEngine.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Templating/TwigEngine.php b/src/Templating/TwigEngine.php index 8c66185..e6ab5c8 100644 --- a/src/Templating/TwigEngine.php +++ b/src/Templating/TwigEngine.php @@ -2,8 +2,10 @@ namespace Pyrite\Templating; +use Symfony\Bridge\Twig\Extension\DumpExtension; use Pyrite\Container\Container; use Pyrite\Templating\Twig\Extension; +use Symfony\Component\VarDumper\Cloner\VarCloner; class TwigEngine implements Engine { @@ -13,12 +15,17 @@ public function __construct(Container $container) { $rootDir = $container->getParameter('root_dir'); $productionMode = $container->getParameter('production_mode'); + $debug = !($productionMode === true); $loader = new \Twig_Loader_Filesystem($rootDir); $this->twig = new \Twig_Environment($loader, array( 'cache' => $rootDir . '/tmp', - 'debug' => !($productionMode === true) + 'debug' => $debug )); + + if ($debug && class_exists('Symfony\Component\VarDumper\Cloner\VarCloner') && class_exists('Symfony\Bridge\Twig\Extension\DumpExtension')) { + $this->twig->addExtension(new DumpExtension(new VarCloner())); + } } public function extendTwig(Extension $extension) From af5469c4832228bdc124d60a6224b6ba79af73a1 Mon Sep 17 00:00:00 2001 From: Alexandre Dupuy Date: Fri, 16 Sep 2016 14:45:41 +0200 Subject: [PATCH 2/2] simplify code --- src/Templating/TwigEngine.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Templating/TwigEngine.php b/src/Templating/TwigEngine.php index e6ab5c8..24ba484 100644 --- a/src/Templating/TwigEngine.php +++ b/src/Templating/TwigEngine.php @@ -2,9 +2,9 @@ namespace Pyrite\Templating; -use Symfony\Bridge\Twig\Extension\DumpExtension; use Pyrite\Container\Container; use Pyrite\Templating\Twig\Extension; +use Symfony\Bridge\Twig\Extension\DumpExtension; use Symfony\Component\VarDumper\Cloner\VarCloner; class TwigEngine implements Engine @@ -15,7 +15,7 @@ public function __construct(Container $container) { $rootDir = $container->getParameter('root_dir'); $productionMode = $container->getParameter('production_mode'); - $debug = !($productionMode === true); + $debug = !$productionMode; $loader = new \Twig_Loader_Filesystem($rootDir); $this->twig = new \Twig_Environment($loader, array( @@ -23,7 +23,7 @@ public function __construct(Container $container) 'debug' => $debug )); - if ($debug && class_exists('Symfony\Component\VarDumper\Cloner\VarCloner') && class_exists('Symfony\Bridge\Twig\Extension\DumpExtension')) { + if ($debug && class_exists(VarCloner::class) && class_exists(DumpExtension::class)) { $this->twig->addExtension(new DumpExtension(new VarCloner())); } }