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 section currently being rendered. |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $sectionName; |
||
44 | |||
45 | /** |
||
46 | * Whether the section should be appended or not. |
||
47 | * @var boolean |
||
48 | */ |
||
49 | protected $appendSection; |
||
50 | |||
51 | /** |
||
52 | * The name of the template layout. |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $layoutName; |
||
56 | |||
57 | /** |
||
58 | * The data assigned to the template layout. |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $layoutData; |
||
62 | |||
63 | /** |
||
64 | * Create new Template instance. |
||
65 | * @param Engine $engine |
||
66 | * @param string $name |
||
67 | */ |
||
68 | 124 | public function __construct(Engine $engine, $name) |
|
75 | |||
76 | /** |
||
77 | * Magic method used to call extension functions. |
||
78 | * @param string $name |
||
79 | * @param array $arguments |
||
80 | * @return mixed |
||
81 | */ |
||
82 | 8 | public function __call($name, $arguments) |
|
86 | |||
87 | /** |
||
88 | * Alias for render() method. |
||
89 | * @throws \Throwable |
||
90 | * @throws \Exception |
||
91 | * @return string |
||
92 | */ |
||
93 | 4 | public function __toString() |
|
97 | |||
98 | /** |
||
99 | * Assign or get template data. |
||
100 | * @param array $data |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 124 | public function data(array $data = null) |
|
111 | |||
112 | /** |
||
113 | * Check if the template exists. |
||
114 | * @return boolean |
||
115 | */ |
||
116 | 108 | public function exists() |
|
120 | |||
121 | /** |
||
122 | * Get the template path. |
||
123 | * @return string |
||
124 | */ |
||
125 | 104 | public function path() |
|
129 | |||
130 | /** |
||
131 | * Render the template and layout. |
||
132 | * @param array $data |
||
133 | * @throws \Throwable |
||
134 | * @throws \Exception |
||
135 | * @return string |
||
136 | */ |
||
137 | 100 | public function render(array $data = array()) |
|
178 | |||
179 | /** |
||
180 | * Set the template's layout. |
||
181 | * @param string $name |
||
182 | * @param array $data |
||
183 | * @return null |
||
184 | */ |
||
185 | 24 | public function layout($name, array $data = array()) |
|
190 | |||
191 | /** |
||
192 | * Start a new section block. |
||
193 | * @param string $name |
||
194 | * @return null |
||
195 | */ |
||
196 | 24 | public function start($name) |
|
212 | |||
213 | /** |
||
214 | * Start a new append section block. |
||
215 | * @param string $name |
||
216 | * @return null |
||
217 | */ |
||
218 | 8 | public function push($name) |
|
224 | |||
225 | /** |
||
226 | * Stop the current section block. |
||
227 | * @return null |
||
228 | */ |
||
229 | 20 | public function stop() |
|
245 | |||
246 | /** |
||
247 | * Alias of stop(). |
||
248 | * @return null |
||
249 | */ |
||
250 | 8 | public function end() |
|
254 | |||
255 | /** |
||
256 | * Returns the content for a section block. |
||
257 | * @param string $name Section name |
||
258 | * @param string $default Default section content |
||
259 | * @return string|null |
||
260 | */ |
||
261 | 24 | public function section($name, $default = null) |
|
269 | |||
270 | /** |
||
271 | * Fetch a rendered template. |
||
272 | * @param string $name |
||
273 | * @param array $data |
||
274 | * @return string |
||
275 | */ |
||
276 | 4 | public function fetch($name, array $data = array()) |
|
280 | |||
281 | /** |
||
282 | * Output a rendered template. |
||
283 | * @param string $name |
||
284 | * @param array $data |
||
285 | * @return null |
||
286 | */ |
||
287 | 4 | public function insert($name, array $data = array()) |
|
291 | |||
292 | /** |
||
293 | * Apply multiple functions to variable. |
||
294 | * @param mixed $var |
||
295 | * @param string $functions |
||
296 | * @return mixed |
||
297 | */ |
||
298 | 12 | public function batch($var, $functions) |
|
314 | |||
315 | /** |
||
316 | * Escape string. |
||
317 | * @param string $string |
||
318 | * @param null|string $functions |
||
319 | * @return string |
||
320 | */ |
||
321 | 12 | public function escape($string, $functions = null) |
|
335 | |||
336 | /** |
||
337 | * Alias to escape function. |
||
338 | * @param string $string |
||
339 | * @param null|string $functions |
||
340 | * @return string |
||
341 | */ |
||
342 | 4 | public function e($string, $functions = null) |
|
346 | } |
||
347 |