Skip to content

Commit

Permalink
twig: add DumpExtension if VarDumper and TwigBridge are available
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDpy committed Sep 16, 2016
1 parent 7551d38 commit 74936f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Templating/TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down

0 comments on commit 74936f2

Please sign in to comment.