/
Part.class.php
50 lines (40 loc) · 1.25 KB
/
Part.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @todo Exception handling
*
* @author Kris
*/
class Part extends AbstractHelper {
protected static $app;
protected static $loaded = array();
public static function init(AbstractView $view) {
$response = $view->getResponse();
self::$app = $response->meta->app;
}
public static function render() {
$args = func_get_args();
$templateFile = self::$app->getViewsDir() . $args[0] . '.part.php';
if(!isset(self::$loaded[$templateFile])) {
$template = file_get_contents($templateFile);
preg_match_all("/assert(?:\W*)\\((?:\W*)(?:is_(.*?)(?:\W*)\\((?:\W*)\\$(.*?)(?:\W*)\\)|\\$(\\w*?)(?:\W*)instanceof(?:\W*)(\\w*?))(?:\W*)\\)(?:\W*);/",
$template,
$matches);
$parameters = array();
foreach($matches[0] as $key => $value) {
if(isset($matches[1][$key]) && $matches[1][$key] != '') {
$parameters[$matches[2][$key]] = $matches[1][$key];
} else if (isset($matches[3][$key])) {
$parameters[$matches[3][$key]] = $matches[4][$key];
}
}
self::$loaded[$templateFile] = $parameters;
}
$parameters = self::$loaded[$templateFile];
$keys = array_keys($parameters);
array_unshift($keys, '');
$params = array_combine($keys, $args);
extract($params);
include($templateFile);
}
}
?>