Skip to content

Commit 96deda8

Browse files
committed
Update to twig 4.x
1 parent 06a9fb9 commit 96deda8

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

src/Support/Functions.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
if (!function_exists('_render')) {
2323
function _render($template, $context)
2424
{
25-
return (new \Twig_Environment(new \Twig_Loader_String))->render($template, $context);
25+
$twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
26+
$template = $twig->createTemplate($template);
27+
return $template->render($context);
2628
}
2729
}
2830

src/Support/TwigParser.php

+5-22
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,17 @@ class TwigParser
1717
{
1818

1919
/**
20-
* The Twig instance
21-
*
22-
* @var Bridge
23-
*/
24-
protected $twig;
25-
26-
/**
27-
* Create a new TwigParser instance
28-
*
29-
* @param UrlGenerator $url
30-
* @param Engine $parser
31-
* @param Request $request
32-
*/
33-
public function __construct()
34-
{
35-
$this->twig = new \Twig_Environment(new \Twig_Loader_String);
36-
$this->twig->addExtension(new TwigExtension());
37-
}
38-
39-
/**
40-
* Parse data into the content
20+
* Create a new TwigParser instance and parse data into the content
4121
*
4222
* @param string $content
4323
* @param array $data
4424
* @return string
4525
*/
4626
public function parse($content, $data = [])
4727
{
48-
return $this->twig->render($content, $data);
28+
$twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
29+
$twig->addExtension(new TwigExtension());
30+
$template = $twig->createTemplate($content);
31+
$subject = $template->render($data);
4932
}
5033
}

0 commit comments

Comments
 (0)