Skip to content

Commit

Permalink
Merge pull request #36 from Evaneos/twig-dump
Browse files Browse the repository at this point in the history
twig: add DumpExtension if VarDumper and TwigBridge are available
  • Loading branch information
Prophet777 authored Sep 16, 2016
2 parents 7551d38 + af5469c commit 3ca8d36
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 @@ -4,6 +4,8 @@

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
{
Expand All @@ -13,12 +15,17 @@ public function __construct(Container $container)
{
$rootDir = $container->getParameter('root_dir');
$productionMode = $container->getParameter('production_mode');
$debug = !$productionMode;

$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(VarCloner::class) && class_exists(DumpExtension::class)) {
$this->twig->addExtension(new DumpExtension(new VarCloner()));
}
}

public function extendTwig(Extension $extension)
Expand Down

0 comments on commit 3ca8d36

Please sign in to comment.