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 | * Alias for render() method. |
||
77 | * @throws \Throwable |
||
78 | * @throws \Exception |
||
79 | * @return string |
||
80 | */ |
||
81 | 4 | public function __toString() |
|
85 | |||
86 | /** |
||
87 | * Assign data to template object. |
||
88 | * @param array $data |
||
89 | * @return null |
||
90 | */ |
||
91 | 104 | public function data(array $data) |
|
95 | |||
96 | /** |
||
97 | * Check if the template exists. |
||
98 | * @return boolean |
||
99 | */ |
||
100 | 92 | public function exists() |
|
104 | |||
105 | /** |
||
106 | * Get the template path. |
||
107 | * @return string |
||
108 | */ |
||
109 | 88 | public function path() |
|
113 | |||
114 | /** |
||
115 | * Render the template and layout. |
||
116 | * @param array $data |
||
117 | * @throws \Throwable |
||
118 | * @throws \Exception |
||
119 | * @return string |
||
120 | */ |
||
121 | 84 | public function render(array $data = array()) |
|
157 | |||
158 | /** |
||
159 | * Set the template's layout. |
||
160 | * @param string $name |
||
161 | * @param array $data |
||
162 | * @return null |
||
163 | */ |
||
164 | 12 | public function layout($name, array $data = array()) |
|
169 | |||
170 | /** |
||
171 | * Start a new section block. |
||
172 | * @param string $name |
||
173 | * @return null |
||
174 | */ |
||
175 | 8 | public function start($name) |
|
187 | |||
188 | /** |
||
189 | * Stop the current section block. |
||
190 | * @return null |
||
191 | */ |
||
192 | 8 | public function stop() |
|
204 | |||
205 | /** |
||
206 | * Returns the content for a section block. |
||
207 | * @param string $name Section name |
||
208 | * @param string $default Default section content |
||
209 | * @return string|null |
||
210 | */ |
||
211 | 12 | public function section($name, $default = null) |
|
219 | |||
220 | /** |
||
221 | * Fetch a rendered template. |
||
222 | * @param string $name |
||
223 | * @param array $data |
||
224 | * @return string |
||
225 | */ |
||
226 | 4 | public function fetch($name, array $data = array()) |
|
230 | |||
231 | /** |
||
232 | * Output a rendered template. |
||
233 | * @param string $name |
||
234 | * @param array $data |
||
235 | * @return null |
||
236 | */ |
||
237 | 4 | public function insert($name, array $data = array()) |
|
241 | |||
242 | /** |
||
243 | * Apply multiple functions to variable. |
||
244 | * @param mixed $var |
||
245 | * @param string $functions |
||
246 | * @return mixed |
||
247 | */ |
||
248 | 12 | public function batch($var, $functions) |
|
264 | |||
265 | /** |
||
266 | * Escape string. |
||
267 | * @param string $string |
||
268 | * @param null|string $functions |
||
269 | * @return string |
||
270 | */ |
||
271 | 12 | public function escape($string, $functions = null) |
|
285 | |||
286 | /** |
||
287 | * Alias to escape function. |
||
288 | * @param string $string |
||
289 | * @param null|string $functions |
||
290 | * @return string |
||
291 | */ |
||
292 | 4 | public function e($string, $functions = null) |
|
296 | } |
||
297 |