|
1
|
|
|
<?php |
|
2
|
|
|
namespace JayaCode\Framework\Core\View\Template; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class BasicTemplate |
|
6
|
|
|
* @package JayaCode\Framework\Core\View\Template |
|
7
|
|
|
*/ |
|
8
|
|
|
class BasicTemplate extends Template |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $parent; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @return string |
|
17
|
|
|
*/ |
|
18
|
3 |
|
public function buildScript() |
|
19
|
|
|
{ |
|
20
|
3 |
|
$fileCache = $this->cacheDir.str_replace(["/", "."], "_", $this->fileTemplate); |
|
21
|
3 |
|
if ($this->cacheDir !== null && file_exists($fileCache) && empty($this->contentParent)) { |
|
22
|
|
|
return $this->script = file_get_contents($fileCache); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
3 |
|
$this->script = $this->converter->build(file_get_contents($this->locTemplate)); |
|
26
|
|
|
|
|
27
|
3 |
|
if ($this->cacheDir !== null && empty($this->contentParent)) { |
|
28
|
|
|
file_put_contents($fileCache, $this->script); |
|
29
|
|
|
} |
|
30
|
3 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return mixed|string |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function render() |
|
36
|
|
|
{ |
|
37
|
3 |
|
if ($this->script === null) { |
|
38
|
3 |
|
$this->buildScript(); |
|
39
|
3 |
|
} |
|
40
|
|
|
|
|
41
|
3 |
|
$varArray = $this->vars->all(); |
|
42
|
3 |
|
extract($varArray); |
|
43
|
|
|
|
|
44
|
3 |
|
ob_start(); |
|
45
|
3 |
|
eval("?>" . $this->script); |
|
|
|
|
|
|
46
|
3 |
|
$result = ob_get_contents(); |
|
47
|
3 |
|
ob_end_clean(); |
|
48
|
|
|
|
|
49
|
3 |
|
if ($this->parent) { |
|
50
|
3 |
|
$fileParent = str_replace(".", "/", $this->parent); |
|
51
|
3 |
|
$fileParent = $fileParent.Template::$extension; |
|
52
|
3 |
|
$parent = new BasicTemplate($this->locView, $fileParent, $this->variableCollector, $this->converter); |
|
53
|
3 |
|
$parent->setContentParent($this->contentParent); |
|
54
|
3 |
|
return $parent->render(); |
|
55
|
|
|
} |
|
56
|
3 |
|
return $result; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param $name |
|
61
|
|
|
*/ |
|
62
|
3 |
|
public function setParent($name) |
|
63
|
|
|
{ |
|
64
|
3 |
|
$this->parent = $name; |
|
65
|
3 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var array |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $contentParent = []; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getContentParent() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->contentParent; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param array $contentParent |
|
82
|
|
|
*/ |
|
83
|
3 |
|
public function setContentParent($contentParent) |
|
84
|
|
|
{ |
|
85
|
3 |
|
$this->contentParent = $contentParent; |
|
86
|
3 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
On one hand,
evalmight be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM,evalprevents some optimization that they perform.