Skip to content

Commit 11730a8

Browse files
committed
Add new TwigEnvironmentDecorator class
1 parent 22a4332 commit 11730a8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace aleksip\DataTransformPlugin\Twig;
4+
5+
use aleksip\DataTransformPlugin\ErrorHandlerTrait;
6+
7+
class TwigEnvironmentDecorator
8+
{
9+
use ErrorHandlerTrait;
10+
11+
protected $environment;
12+
protected $errno;
13+
protected $errstr;
14+
15+
public function __construct(\Twig_Environment $environment)
16+
{
17+
$this->environment = $environment;
18+
}
19+
20+
public function addGlobal($name, $value)
21+
{
22+
$this->environment->addGlobal($name, $value);
23+
}
24+
25+
public function render($name, array $context = [])
26+
{
27+
$this->setErrorHandler();
28+
$this->environment->render($name, $context);
29+
$this->restoreErrorHandler();
30+
}
31+
32+
public function __call($method, $args)
33+
{
34+
if ($method == 'errorHandler') {
35+
return $this->errorHandler(...$args);
36+
}
37+
else {
38+
return call_user_func_array([$this->environment, $method], $args);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)