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 | 108 | 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 | 108 | public function data(array $data = null) |
|
99 | |||
100 | /** |
||
101 | * Check if the template exists. |
||
102 | * @return boolean |
||
103 | */ |
||
104 | 92 | public function exists() |
|
108 | |||
109 | /** |
||
110 | * Get the template path. |
||
111 | * @return string |
||
112 | */ |
||
113 | 88 | public function path() |
|
117 | |||
118 | /** |
||
119 | * Render the template and layout. |
||
120 | * @param array $data |
||
121 | * @throws \Throwable |
||
122 | * @throws \Exception |
||
123 | * @return string |
||
124 | */ |
||
125 | 84 | public function render(array $data = array()) |
|
161 | |||
162 | /** |
||
163 | * Set the template's layout. |
||
164 | * @param string $name |
||
165 | * @param array $data |
||
166 | * @return null |
||
167 | */ |
||
168 | 12 | public function layout($name, array $data = array()) |
|
173 | |||
174 | /** |
||
175 | * Start a new section block. |
||
176 | * @param string $name |
||
177 | * @return null |
||
178 | */ |
||
179 | 8 | public function start($name) |
|
191 | |||
192 | /** |
||
193 | * Stop the current section block. |
||
194 | * @return null |
||
195 | */ |
||
196 | 8 | public function stop() |
|
208 | |||
209 | /** |
||
210 | * Returns the content for a section block. |
||
211 | * @param string $name Section name |
||
212 | * @param string $default Default section content |
||
213 | * @return string|null |
||
214 | */ |
||
215 | 12 | public function section($name, $default = null) |
|
223 | |||
224 | /** |
||
225 | * Fetch a rendered template. |
||
226 | * @param string $name |
||
227 | * @param array $data |
||
228 | * @return string |
||
229 | */ |
||
230 | 4 | public function fetch($name, array $data = array()) |
|
234 | |||
235 | /** |
||
236 | * Output a rendered template. |
||
237 | * @param string $name |
||
238 | * @param array $data |
||
239 | * @return null |
||
240 | */ |
||
241 | 4 | public function insert($name, array $data = array()) |
|
245 | |||
246 | /** |
||
247 | * Apply multiple functions to variable. |
||
248 | * @param mixed $var |
||
249 | * @param string $functions |
||
250 | * @return mixed |
||
251 | */ |
||
252 | 12 | public function batch($var, $functions) |
|
268 | |||
269 | /** |
||
270 | * Escape string. |
||
271 | * @param string $string |
||
272 | * @param null|string $functions |
||
273 | * @return string |
||
274 | */ |
||
275 | 12 | public function escape($string, $functions = null) |
|
289 | |||
290 | /** |
||
291 | * Alias to escape function. |
||
292 | * @param string $string |
||
293 | * @param null|string $functions |
||
294 | * @return string |
||
295 | */ |
||
296 | 4 | public function e($string, $functions = null) |
|
300 | } |
||
301 |