Commit edccec37 authored by Avris's avatar Avris

dump function

parent 6d823712
......@@ -38,3 +38,8 @@ To register that extension using Micrus's DI, just declare it with a tag `twigEx
myTwigExtension:
class: App\Service\MyTwigExtension
tags: [twigExtension]
### Copyright ###
* **Author:** Andrzej Prusinowski [(Avris.it)](https://avris.it)
* **Licence:** [MIT](https://opensource.org/licenses/MIT)
......@@ -10,7 +10,7 @@ class TwigModule implements Module
return [
'services' => [
'templater' => [
'class' => __NAMESPACE__ . '\TwigTemplater',
'class' => TwigTemplater::class,
'parameters' => ['@container', '{@rootDir}/run/cache/{@env}/twig'],
'events' => ['cacheWarmup'],
],
......
......@@ -4,6 +4,7 @@ namespace Avris\Micrus\Twig;
use Avris\Micrus\Container;
use Avris\Micrus\Exception\NotFoundException;
use Avris\Micrus\Tool\Cache\CacheWarmupEvent;
use Avris\Micrus\Tool\VarDumper;
use Avris\Micrus\View\Templater;
class TwigTemplater extends Templater
......@@ -64,6 +65,15 @@ class TwigTemplater extends Templater
'isGranted',
[$this, 'isGranted']
));
if (class_exists('Symfony\Component\VarDumper\Dumper\HtmlDumper')) {
$dumper = new VarDumper();
$this->twig->addFunction(new \Twig_SimpleFunction(
'dump',
function ($var, $html = true) use ($dumper) { return $dumper->dump($var, $html); },
['is_safe' => ['html']]
));
}
}
/**
......
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