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 $currentSection; |
||
44 | |||
45 | /** |
||
46 | * The name of the template layout. |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $layoutName; |
||
50 | |||
51 | /** |
||
52 | * The data assigned to the template layout. |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $layoutData; |
||
56 | |||
57 | /** |
||
58 | * Create new Template instance. |
||
59 | * @param Engine $engine |
||
60 | * @param string $name |
||
61 | */ |
||
62 | 124 | public function __construct(Engine $engine, $name) |
|
69 | |||
70 | /** |
||
71 | * Magic method used to call extension functions. |
||
72 | * @param string $name |
||
73 | * @param array $arguments |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 8 | public function __call($name, $arguments) |
|
80 | |||
81 | /** |
||
82 | * Alias for render() method. |
||
83 | * @throws \Throwable |
||
84 | * @throws \Exception |
||
85 | * @return string |
||
86 | */ |
||
87 | 4 | public function __toString() |
|
91 | |||
92 | /** |
||
93 | * Assign or get template data. |
||
94 | * @param array $data |
||
95 | * @return mixed |
||
96 | */ |
||
97 | 124 | public function data(array $data = null) |
|
105 | |||
106 | /** |
||
107 | * Check if the template exists. |
||
108 | * @return boolean |
||
109 | */ |
||
110 | 108 | public function exists() |
|
114 | |||
115 | /** |
||
116 | * Get the template path. |
||
117 | * @return string |
||
118 | */ |
||
119 | 104 | public function path() |
|
123 | |||
124 | /** |
||
125 | * Render the template and layout. |
||
126 | * @param array $data |
||
127 | * @throws \Throwable |
||
128 | * @throws \Exception |
||
129 | * @return string |
||
130 | */ |
||
131 | 100 | public function render(array $data = array()) |
|
172 | |||
173 | /** |
||
174 | * Set the template's layout. |
||
175 | * @param string $name |
||
176 | * @param array $data |
||
177 | * @return null |
||
178 | */ |
||
179 | 20 | public function layout($name, array $data = array()) |
|
184 | |||
185 | /** |
||
186 | * Start a new section block. |
||
187 | * @param string $name |
||
188 | * @return null |
||
189 | */ |
||
190 | 20 | public function start($name) |
|
206 | |||
207 | /** |
||
208 | * Stop the current section block. |
||
209 | * @return null |
||
210 | */ |
||
211 | 16 | public function stop() |
|
222 | |||
223 | /** |
||
224 | * Stop the current section block and append the results. |
||
225 | * @return null |
||
226 | */ |
||
227 | 12 | public function append() |
|
238 | |||
239 | /** |
||
240 | * Returns the content for a section block. |
||
241 | * @param string $name Section name |
||
242 | * @param string $default Default section content |
||
243 | * @return string|null |
||
244 | */ |
||
245 | 20 | public function section($name, $default = null) |
|
253 | |||
254 | /** |
||
255 | * Fetch a rendered template. |
||
256 | * @param string $name |
||
257 | * @param array $data |
||
258 | * @return string |
||
259 | */ |
||
260 | 4 | public function fetch($name, array $data = array()) |
|
264 | |||
265 | /** |
||
266 | * Output a rendered template. |
||
267 | * @param string $name |
||
268 | * @param array $data |
||
269 | * @return null |
||
270 | */ |
||
271 | 4 | public function insert($name, array $data = array()) |
|
275 | |||
276 | /** |
||
277 | * Apply multiple functions to variable. |
||
278 | * @param mixed $var |
||
279 | * @param string $functions |
||
280 | * @return mixed |
||
281 | */ |
||
282 | 12 | public function batch($var, $functions) |
|
298 | |||
299 | /** |
||
300 | * Escape string. |
||
301 | * @param string $string |
||
302 | * @param null|string $functions |
||
303 | * @return string |
||
304 | */ |
||
305 | 12 | public function escape($string, $functions = null) |
|
319 | |||
320 | /** |
||
321 | * Alias to escape function. |
||
322 | * @param string $string |
||
323 | * @param null|string $functions |
||
324 | * @return string |
||
325 | */ |
||
326 | 4 | public function e($string, $functions = null) |
|
330 | } |
||
331 |