Skip to content

Commit c4b1464

Browse files
committed
Added retrocompability between Twig v1 and v2
1 parent 953502c commit c4b1464

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Renderers/TwigRenderer.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,31 @@ public function __construct(array $templates_dirs, array $options = array())
2727
{
2828
$loaders = new ChainLoader();
2929

30+
if (class_exists('Twig_Loader_Filesystem')) {
31+
$class = 'Twig_Loader_Filesystem';
32+
$envClass = 'Twig_Environment';
33+
} else {
34+
$class = 'FilesystemLoader';
35+
$envClass = 'Environment';
36+
}
37+
3038
foreach ($templates_dirs as $template_dir) {
31-
$loaders->addLoader(new FilesystemLoader($template_dir));
39+
$loaders->addLoader(new $class($template_dir));
3240
}
3341

34-
$this->twig = new Environment($loaders, $options);
42+
$this->twig = new $envClass($loaders, $options);
3543
$this->setFilters();
3644
}
3745

3846
public function setFilters()
3947
{
40-
$filter_merge_str = new TwigFilter('merge_str', function ($attrs, array $options = array()) {
48+
if (class_exists('Twig_SimpleFilter')) {
49+
$class = 'Twig_SimpleFilter';
50+
} else {
51+
$class = 'TwigFilter';
52+
}
53+
54+
$filter_merge_str = new $class('merge_str', function ($attrs, array $options = array()) {
4155
$key = $options[0];
4256
$value = $options[1];
4357

0 commit comments

Comments
 (0)