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 = array(); |
||
32 | |||
33 | /** |
||
34 | * An array of section content. |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $sections = array(); |
||
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 | * @param string $name |
||
55 | */ |
||
56 | 104 | 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 | * @return mixed |
||
69 | */ |
||
70 | 8 | public function __call($name, $arguments) |
|
74 | |||
75 | /** |
||
76 | * Assign data to template object. |
||
77 | * @param array $data |
||
78 | * @return null |
||
79 | */ |
||
80 | 104 | public function data(array $data) |
|
84 | |||
85 | /** |
||
86 | * Check if the template exists. |
||
87 | * @return boolean |
||
88 | */ |
||
89 | 92 | public function exists() |
|
93 | |||
94 | /** |
||
95 | * Get the template path. |
||
96 | * @return string |
||
97 | */ |
||
98 | 88 | public function path() |
|
102 | |||
103 | /** |
||
104 | * Render the template and layout. |
||
105 | * @param array $data |
||
106 | * @throws \Throwable |
||
107 | * @throws \Exception |
||
108 | * @return string |
||
109 | */ |
||
110 | 84 | public function render(array $data = array()) |
|
146 | |||
147 | /** |
||
148 | * Set the template's layout. |
||
149 | * @param string $name |
||
150 | * @param array $data |
||
151 | * @return null |
||
152 | */ |
||
153 | 12 | public function layout($name, array $data = array()) |
|
158 | |||
159 | /** |
||
160 | * Start a new section block. |
||
161 | * @param string $name |
||
162 | * @return null |
||
163 | */ |
||
164 | 8 | public function start($name) |
|
176 | |||
177 | /** |
||
178 | * Stop the current section block. |
||
179 | * @return null |
||
180 | */ |
||
181 | 8 | public function stop() |
|
193 | |||
194 | /** |
||
195 | * Returns the content for a section block. |
||
196 | * @param string $name Section name |
||
197 | * @param string $default Default section content |
||
198 | * @return string|null |
||
199 | */ |
||
200 | 12 | public function section($name, $default = null) |
|
208 | |||
209 | /** |
||
210 | * Fetch a rendered template. |
||
211 | * @param string $name |
||
212 | * @param array $data |
||
213 | * @return string |
||
214 | */ |
||
215 | 4 | public function fetch($name, array $data = array()) |
|
219 | |||
220 | /** |
||
221 | * Output a rendered template. |
||
222 | * @param string $name |
||
223 | * @param array $data |
||
224 | * @return null |
||
225 | */ |
||
226 | 4 | public function insert($name, array $data = array()) |
|
230 | |||
231 | /** |
||
232 | * Apply multiple functions to variable. |
||
233 | * @param mixed $var |
||
234 | * @param string $functions |
||
235 | * @return mixed |
||
236 | */ |
||
237 | 12 | public function batch($var, $functions) |
|
253 | |||
254 | /** |
||
255 | * Escape string. |
||
256 | * @param string $string |
||
257 | * @param null|string $functions |
||
258 | * @return string |
||
259 | */ |
||
260 | 12 | public function escape($string, $functions = null) |
|
274 | |||
275 | /** |
||
276 | * Alias to escape function. |
||
277 | * @param string $string |
||
278 | * @param null|string $functions |
||
279 | * @return string |
||
280 | */ |
||
281 | 4 | public function e($string, $functions = null) |
|
285 | |||
286 | /** |
||
287 | * Alias for render() |
||
288 | * @return string |
||
289 | */ |
||
290 | 4 | public function __toString() |
|
294 | } |
||
295 |