1 | <?php |
||
13 | class Template |
||
14 | { |
||
15 | /** |
||
16 | * Instance of the template engine. |
||
17 | * @var Engine |
||
18 | */ |
||
19 | protected $engine; |
||
20 | |||
21 | /** |
||
22 | * The name of the template. |
||
23 | * @var Name |
||
24 | */ |
||
25 | protected $name; |
||
26 | |||
27 | /** |
||
28 | * The data assigned to the template. |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $data = []; |
||
32 | |||
33 | /** |
||
34 | * An array of section content. |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $sections = []; |
||
38 | |||
39 | /** |
||
40 | * The name of the template layout. |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $layoutName; |
||
44 | |||
45 | /** |
||
46 | * The data assigned to the template layout. |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $layoutData; |
||
50 | |||
51 | /** |
||
52 | * Create new Template instance. |
||
53 | * @param Engine $engine |
||
54 | 100 | * @param string $name |
|
55 | */ |
||
56 | 100 | public function __construct(Engine $engine, $name) |
|
63 | |||
64 | /** |
||
65 | * Magic method used to call extension functions. |
||
66 | * @param string $name |
||
67 | * @param array $arguments |
||
68 | 8 | * @return mixed |
|
69 | */ |
||
70 | 8 | public function __call($name, $arguments) |
|
74 | |||
75 | /** |
||
76 | * Assign data to template object. |
||
77 | * @param array $data |
||
78 | 100 | * @return null |
|
79 | */ |
||
80 | 100 | public function data(array $data) |
|
84 | |||
85 | /** |
||
86 | * Check if the template exists. |
||
87 | 88 | * @return boolean |
|
88 | */ |
||
89 | 88 | public function exists() |
|
93 | |||
94 | /** |
||
95 | * Get the template path. |
||
96 | 84 | * @return string |
|
97 | */ |
||
98 | 84 | public function path() |
|
102 | |||
103 | /** |
||
104 | * Render the template and layout. |
||
105 | * @param array $data |
||
106 | * @throws \Throwable |
||
107 | * @throws \Exception |
||
108 | 80 | * @return string |
|
109 | */ |
||
110 | public function render(array $data = []) |
||
146 | |||
147 | /** |
||
148 | 20 | * Set the template's layout. |
|
149 | * @param string $name |
||
150 | 20 | * @param array $data |
|
151 | 20 | * @return null |
|
152 | */ |
||
153 | protected function layout($name, array $data = []) |
||
158 | |||
159 | /** |
||
160 | 12 | * Start a new section block. |
|
161 | * @param string $name |
||
162 | 12 | * @return null |
|
163 | 12 | */ |
|
164 | 12 | protected function start($name) |
|
176 | 4 | ||
177 | /** |
||
178 | * Stop the current section block. |
||
179 | 4 | * @return null |
|
180 | */ |
||
181 | 4 | protected function stop() |
|
193 | 4 | ||
194 | /** |
||
195 | * Returns the content for a section block. |
||
196 | 4 | * @param string $name Section name |
|
197 | * @param string $default Default section content |
||
198 | 4 | * @return string|null |
|
199 | 4 | */ |
|
200 | protected function section($name, $default = null) |
||
208 | |||
209 | 12 | /** |
|
210 | 8 | * Fetch a rendered template. |
|
211 | * @param string $name |
||
212 | * @param array $data |
||
213 | 4 | * @return string |
|
214 | */ |
||
215 | protected function fetch($name, array $data = []) |
||
219 | |||
220 | /** |
||
221 | * Output a rendered template. |
||
222 | 4 | * @param string $name |
|
223 | * @param array $data |
||
224 | 4 | * @return null |
|
225 | */ |
||
226 | protected function insert($name, array $data = []) |
||
230 | |||
231 | /** |
||
232 | * Apply multiple functions to variable. |
||
233 | 4 | * @param mixed $var |
|
234 | * @param string $functions |
||
235 | 4 | * @return mixed |
|
236 | 4 | */ |
|
237 | protected function batch($var, $functions) |
||
253 | 4 | ||
254 | 4 | /** |
|
255 | * Escape string. |
||
256 | 8 | * @param string $string |
|
257 | * @param null|string $functions |
||
258 | 8 | * @return string |
|
259 | */ |
||
260 | protected function escape($string, $functions = null) |
||
274 | |||
275 | 12 | /** |
|
276 | 4 | * Alias to escape function. |
|
277 | 4 | * @param string $string |
|
278 | * @param null|string $functions |
||
279 | 12 | * @return string |
|
280 | */ |
||
281 | protected function e($string, $functions = null) |
||
285 | } |
||
286 |