1
|
|
|
<?php |
2
|
|
|
namespace JayaCode\Framework\Core\View\Template; |
3
|
|
|
|
4
|
|
|
use JayaCode\Framework\Core\View\Converter\Converter; |
5
|
|
|
use JayaCode\Framework\Core\View\VariableCollector\VariableCollector; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Template |
9
|
|
|
* @property VariableCollector vars |
10
|
|
|
* @package JayaCode\Framework\Core\View\Template |
11
|
|
|
*/ |
12
|
|
|
abstract class Template |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var |
16
|
|
|
*/ |
17
|
|
|
public static $extension; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $locTemplate; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $fileTemplate; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var null |
30
|
|
|
*/ |
31
|
|
|
protected $script = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var Converter |
35
|
|
|
*/ |
36
|
|
|
protected $converter; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var |
40
|
|
|
*/ |
41
|
|
|
protected $locView; |
42
|
|
|
/** |
43
|
|
|
* @var null|string |
44
|
|
|
*/ |
45
|
|
|
protected $cacheDir; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var VariableCollector |
49
|
|
|
*/ |
50
|
|
|
protected $variableCollector; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Template constructor. |
54
|
|
|
* @param $locView |
55
|
|
|
* @param $fileTemplate |
56
|
|
|
* @param VariableCollector $variableCollector |
57
|
|
|
* @param Converter $converter |
58
|
|
|
* @param null $cacheDir |
59
|
|
|
* @throws \Exception |
60
|
|
|
*/ |
61
|
|
|
public function __construct( |
62
|
|
|
$locView, |
63
|
|
|
$fileTemplate, |
64
|
|
|
VariableCollector $variableCollector, |
65
|
|
|
Converter $converter, |
66
|
|
|
$cacheDir = null |
67
|
|
|
) { |
68
|
|
|
$this->variableCollector = $variableCollector; |
69
|
|
|
|
70
|
|
|
$this->locView = $locView; |
71
|
|
|
$this->fileTemplate = $fileTemplate; |
72
|
|
|
$this->locTemplate = $this->locView.$fileTemplate; |
73
|
|
|
$this->converter = $converter; |
74
|
|
|
$this->cacheDir = $cacheDir?rtrim($cacheDir, "/")."/":null; |
75
|
|
|
|
76
|
|
|
if (!file_exists($this->locTemplate)) { |
77
|
|
|
throw new \Exception("not found file or directory {$fileTemplate}"); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (!is_readable($this->locTemplate)) { |
81
|
|
|
throw new \Exception("Template not readable: $this->locTemplate", 4); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
|
|
abstract public function render(); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param $name |
92
|
|
|
* @return VariableCollector|null |
93
|
|
|
*/ |
94
|
|
|
public function __get($name) |
95
|
|
|
{ |
96
|
|
|
return $name == "vars"?$this->variableCollector:null; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function getScript() |
103
|
|
|
{ |
104
|
|
|
return $this->script; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param mixed $script |
109
|
|
|
*/ |
110
|
|
|
public function setScript($script) |
111
|
|
|
{ |
112
|
|
|
$this->script = $script; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getLocTemplates() |
119
|
|
|
{ |
120
|
|
|
return $this->locTemplate; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $locTemplate |
125
|
|
|
*/ |
126
|
|
|
public function setLocTemplate($locTemplate) |
127
|
|
|
{ |
128
|
|
|
$this->locTemplate = $locTemplate; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|