1 | <?php |
||
15 | class TwigEngine extends Twig_Environment implements TemplateEngine |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * An array of template variables available when rendering a template. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $variables = []; |
||
24 | |||
25 | /** |
||
26 | * Create a new Twig engine and add the Stitcher specific template functions. |
||
27 | * |
||
28 | * @param string $templateDir |
||
29 | * @param TemplatePlugin $templatePlugin |
||
30 | */ |
||
31 | public function __construct(string $templateDir, TemplatePlugin $templatePlugin) { |
||
32 | $loader = new Twig_Loader_Filesystem($templateDir); |
||
33 | |||
34 | parent::__construct($loader, [ |
||
35 | 'cache' => false, |
||
36 | ]); |
||
37 | |||
38 | $this->addFunction(new \Twig_SimpleFunction('meta', [$templatePlugin, 'meta'], ['is_safe' => ['html'],])); |
||
39 | $this->addFunction(new \Twig_SimpleFunction('css', [$templatePlugin, 'css'], ['is_safe' => ['html'],])); |
||
40 | $this->addFunction(new \Twig_SimpleFunction('js', [$templatePlugin, 'js'], ['is_safe' => ['html'],])); |
||
41 | $this->addFunction(new \Twig_SimpleFunction('image', [$templatePlugin, 'image'])); |
||
42 | $this->addFunction(new \Twig_SimpleFunction('file', [$templatePlugin, 'file'])); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function renderTemplate(SplFileInfo $template) { |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function addTemplateVariables(array $variables) { |
||
60 | |||
61 | /** |
||
62 | * Check whether a template variable is set |
||
63 | * |
||
64 | * @param string $name |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function hasTemplateVariable(string $name) : bool { |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function clearTemplateVariables() { |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function addTemplateVariable($name, $value) { |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function clearTemplateVariable($variable) { |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function getTemplateExtension() { |
||
105 | } |
||
106 |