Commit b397b680 authored by Avris's avatar Avris

v4.0

parent e31d8157
......@@ -7,10 +7,13 @@ use Avris\Micrus\View\TemplateHelper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\TwigFunction;
final class TwigEngine implements EngineInterface, EventSubscriberInterface
{
/** @var \Twig_Environment */
/** @var Environment */
private $twig;
/** @var string[] */
......@@ -24,7 +27,7 @@ final class TwigEngine implements EngineInterface, EventSubscriberInterface
array $twigExtensions
) {
$this->dirs = $dirs;
$this->twig = new \Twig_Environment(
$this->twig = new Environment(
new Loader($dirs),
[
'cache' => $cacheDir,
......@@ -44,29 +47,29 @@ final class TwigEngine implements EngineInterface, EventSubscriberInterface
{
$this->twig->addGlobal('app', $helper->getApp());
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'route',
[$helper, 'route'],
['is_safe' => ['html_attr']]
));
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'routeExists',
[$helper, 'routeExists']
));
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'asset',
[$helper, 'asset'],
['is_safe' => ['html_attr']]
));
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'isGranted',
[$helper, 'isGranted']
));
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'canAccess',
[$helper, 'canAccess']
));
......@@ -76,7 +79,7 @@ final class TwigEngine implements EngineInterface, EventSubscriberInterface
$htmlDumper = new HtmlDumper();
$cliDumper = new CliDumper();
$this->twig->addFunction(new \Twig_SimpleFunction(
$this->twig->addFunction(new TwigFunction(
'dump',
function ($var, $html = true) use ($cloner, $htmlDumper, $cliDumper) {
$dumper = $html ? $htmlDumper : $cliDumper;
......@@ -99,12 +102,12 @@ final class TwigEngine implements EngineInterface, EventSubscriberInterface
$this->twig->load($template);
return true;
} catch (\Twig_Error_Loader $e) {
} catch (LoaderError $e) {
return false;
}
}
public function getTwig(): \Twig_Environment
public function getTwig(): Environment
{
return $this->twig;
}
......@@ -119,7 +122,7 @@ final class TwigEngine implements EngineInterface, EventSubscriberInterface
if (!$file->isDir()) {
try {
$this->twig->load(substr($filename, strlen($dir) + 1));
} catch (\Twig_Error $e) {}
} catch (LoaderError $e) {}
}
}
}
......
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