1 | <?php |
||
11 | class Twig implements ViewInterface |
||
12 | { |
||
13 | /** |
||
14 | * Twig environment |
||
15 | * @var \Twig_Environment |
||
16 | */ |
||
17 | protected $twig; |
||
18 | |||
19 | /** |
||
20 | * Class constructor |
||
21 | * |
||
22 | * @param \Twig_Environment|array $options |
||
23 | */ |
||
24 | 20 | public function __construct($options) |
|
35 | |||
36 | /** |
||
37 | * Create a new Twig environment |
||
38 | * |
||
39 | * @param array $options |
||
40 | * @return \Twig_Environment |
||
41 | */ |
||
42 | 2 | protected function createTwigEnvironment(array $options) |
|
53 | |||
54 | /** |
||
55 | * Add paths to Twig loader |
||
56 | * |
||
57 | * @param \Twig_Loader_Filesystem $loader |
||
58 | * @param string|array $paths |
||
59 | * @return type |
||
60 | */ |
||
61 | 1 | protected function addLoaderPaths(\Twig_Loader_Filesystem $loader, $paths) |
|
71 | |||
72 | /** |
||
73 | * Get Twig environment |
||
74 | * |
||
75 | * @return \Twig_Environment |
||
76 | */ |
||
77 | 14 | public function getTwig() |
|
81 | |||
82 | |||
83 | /** |
||
84 | * Assert valid variable, function and filter name |
||
85 | * |
||
86 | * @param string $name |
||
87 | * @throws \InvalidArgumentException |
||
88 | */ |
||
89 | 10 | protected function assertViewVariableName($name) |
|
100 | |||
101 | /** |
||
102 | * Expose a function to the view. |
||
103 | * |
||
104 | * @param string $name Function name in template |
||
105 | * @param callable|null $function |
||
106 | * @param string $as 'function' or 'filter' |
||
107 | * @return $this |
||
108 | */ |
||
109 | 10 | public function expose($name, $function = null, $as = 'function') |
|
126 | |||
127 | /** |
||
128 | * Add the official Twig extension and Jansy Twig extensions. |
||
129 | * |
||
130 | * @link https://github.com/twigphp/Twig-extensions |
||
131 | * @link https://github.com/jasny/twig-extensions |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | 1 | public function addDefaultExtensions() |
|
155 | |||
156 | /** |
||
157 | * Get the filename |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 5 | protected function getFilename($name) |
|
169 | |||
170 | /** |
||
171 | * Render and output template |
||
172 | * |
||
173 | * @param ResponseInterface $response |
||
174 | * @param string $name Template name |
||
175 | * @param array $context Template context as associated array |
||
176 | * @return ResponseInterface |
||
177 | */ |
||
178 | 5 | public function render(ResponseInterface $response, $name, array $context = []) |
|
192 | } |
||
193 | |||
194 |