1 | <?php |
||
18 | class Engine |
||
19 | { |
||
20 | /** |
||
21 | * Default template directory. |
||
22 | * @var Directory |
||
23 | */ |
||
24 | protected $directory; |
||
25 | |||
26 | /** |
||
27 | * Template file extension. |
||
28 | * @var FileExtension |
||
29 | */ |
||
30 | protected $fileExtension; |
||
31 | |||
32 | /** |
||
33 | * Collection of template folders. |
||
34 | * @var Folders |
||
35 | */ |
||
36 | protected $folders; |
||
37 | |||
38 | /** |
||
39 | * Collection of template functions. |
||
40 | * @var Functions |
||
41 | */ |
||
42 | protected $functions; |
||
43 | |||
44 | /** |
||
45 | * Collection of preassigned template data. |
||
46 | * @var Data |
||
47 | */ |
||
48 | protected $data; |
||
49 | |||
50 | /** |
||
51 | * Create new Engine instance. |
||
52 | * @param string $directory |
||
53 | * @param string $fileExtension |
||
54 | */ |
||
55 | 158 | public function __construct($directory = null, $fileExtension = 'php') |
|
63 | |||
64 | /** |
||
65 | * Set path to templates directory. |
||
66 | * @param string|null $directory Pass null to disable the default directory. |
||
67 | * @return Engine |
||
68 | */ |
||
69 | 8 | public function setDirectory($directory) |
|
75 | |||
76 | /** |
||
77 | * Get path to templates directory. |
||
78 | * @return string |
||
79 | */ |
||
80 | 76 | public function getDirectory() |
|
84 | |||
85 | /** |
||
86 | * Set the template file extension. |
||
87 | * @param string|null $fileExtension Pass null to manually set it. |
||
88 | * @return Engine |
||
89 | */ |
||
90 | 6 | public function setFileExtension($fileExtension) |
|
96 | |||
97 | /** |
||
98 | * Get the template file extension. |
||
99 | * @return string |
||
100 | */ |
||
101 | 100 | public function getFileExtension() |
|
105 | |||
106 | /** |
||
107 | * Add a new template folder for grouping templates under different namespaces. |
||
108 | * @param string $name |
||
109 | * @param string $directory |
||
110 | * @param boolean $fallback |
||
111 | * @return Engine |
||
112 | */ |
||
113 | 42 | public function addFolder($name, $directory, $fallback = false) |
|
119 | |||
120 | /** |
||
121 | * Remove a template folder. |
||
122 | * @param string $name |
||
123 | * @return Engine |
||
124 | */ |
||
125 | 2 | public function removeFolder($name) |
|
131 | |||
132 | /** |
||
133 | * Get collection of all template folders. |
||
134 | * @return Folders |
||
135 | */ |
||
136 | 16 | public function getFolders() |
|
140 | |||
141 | /** |
||
142 | * Add preassigned template data. |
||
143 | * @param array $data; |
||
144 | * @param null|string|array $templates; |
||
145 | * @return Engine |
||
146 | */ |
||
147 | 6 | public function addData(array $data, $templates = null) |
|
153 | |||
154 | /** |
||
155 | * Get all preassigned template data. |
||
156 | * @param null|string $template; |
||
157 | * @return array |
||
158 | */ |
||
159 | 68 | public function getData($template = null) |
|
163 | |||
164 | /** |
||
165 | * Register a new template function. |
||
166 | * @param string $name; |
||
167 | * @param callback $callback; |
||
168 | * @return Engine |
||
169 | */ |
||
170 | 78 | public function registerFunction($name, $callback) |
|
176 | |||
177 | /** |
||
178 | * Remove a template function. |
||
179 | * @param string $name; |
||
180 | * @return Engine |
||
181 | */ |
||
182 | 4 | public function dropFunction($name) |
|
188 | |||
189 | /** |
||
190 | * Get a template function. |
||
191 | * @param string $name |
||
192 | * @return Func |
||
193 | */ |
||
194 | 10 | public function getFunction($name) |
|
198 | |||
199 | /** |
||
200 | * Check if a template function exists. |
||
201 | * @param string $name |
||
202 | * @return boolean |
||
203 | */ |
||
204 | 20 | public function doesFunctionExist($name) |
|
208 | |||
209 | /** |
||
210 | * Load an extension. |
||
211 | * @param ExtensionInterface $extension |
||
212 | * @return Engine |
||
213 | */ |
||
214 | 4 | public function loadExtension(ExtensionInterface $extension) |
|
220 | |||
221 | /** |
||
222 | * Load multiple extensions. |
||
223 | * @param array $extensions |
||
224 | * @return Engine |
||
225 | */ |
||
226 | 2 | public function loadExtensions(array $extensions = array()) |
|
234 | |||
235 | /** |
||
236 | * Get a template path. |
||
237 | * @param string $name |
||
238 | * @return string |
||
239 | */ |
||
240 | 2 | public function path($name) |
|
246 | |||
247 | /** |
||
248 | * Check if a template exists. |
||
249 | * @param string $name |
||
250 | * @return boolean |
||
251 | */ |
||
252 | 2 | public function exists($name) |
|
258 | |||
259 | /** |
||
260 | * Create a new template. |
||
261 | * @param string $name |
||
262 | * @return Template |
||
263 | */ |
||
264 | 20 | public function make($name) |
|
268 | |||
269 | /** |
||
270 | * Create a new template and render it. |
||
271 | * @param string $name |
||
272 | * @param array $data |
||
273 | * @return string |
||
274 | */ |
||
275 | 6 | public function render($name, array $data = array()) |
|
279 | } |
||
280 |