|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* View adapter and singleton functionality |
|
4
|
|
|
* |
|
5
|
|
|
* @file ViewAdapterAbstract.php |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 5.4+ |
|
8
|
|
|
* |
|
9
|
|
|
* @author Alexander Yancharuk <alex at itvault dot info> |
|
10
|
|
|
* @copyright © 2012-2015 Alexander Yancharuk <alex at itvault at info> |
|
11
|
|
|
* @date Чтв Сен 5 15:10:46 MSK 2013 |
|
12
|
|
|
* @license The BSD 3-Clause License |
|
13
|
|
|
* <https://tldrlegal.com/license/bsd-3-clause-license-(revised)> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Veles\View\Adapters; |
|
17
|
|
|
|
|
18
|
|
|
use Traits\LazyCalls; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class ViewAdapterAbstract |
|
22
|
|
|
* |
|
23
|
|
|
* @author Alexander Yancharuk <alex at itvault dot info> |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class ViewAdapterAbstract |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var mixed */ |
|
28
|
|
|
protected $driver; |
|
29
|
|
|
/** @var mixed */ |
|
30
|
|
|
protected $variables; |
|
31
|
|
|
|
|
32
|
|
|
use LazyCalls; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Driver initialization |
|
36
|
|
|
*/ |
|
37
|
|
|
abstract protected function __construct(); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Output method |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $path Path to template |
|
43
|
|
|
*/ |
|
44
|
|
|
abstract public function show($path); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Output View into buffer and save it in variable |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $path Path to template |
|
50
|
|
|
* @return string View content |
|
51
|
|
|
*/ |
|
52
|
|
|
abstract public function get($path); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Check template cache status |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $tpl Template file |
|
58
|
|
|
* @return bool Cache status |
|
59
|
|
|
*/ |
|
60
|
|
|
abstract public function isCached($tpl); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get adapter driver |
|
64
|
|
|
* |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getDriver() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->driver; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Set adapter driver |
|
74
|
|
|
* |
|
75
|
|
|
* @param mixed $driver |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setDriver($driver) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->driver = $driver; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Method for output variables setup |
|
84
|
|
|
* |
|
85
|
|
|
* @param mixed $vars Output variables or traversable class |
|
86
|
|
|
*/ |
|
87
|
|
|
public function set($vars = []) |
|
88
|
|
|
{ |
|
89
|
|
|
foreach ($vars as $prop => $value) { |
|
90
|
|
|
$this->variables[$prop] = $value; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Output variables cleanup |
|
96
|
|
|
* |
|
97
|
|
|
* @param array $vars Array of variables names |
|
98
|
|
|
*/ |
|
99
|
|
|
public function del(array $vars) |
|
100
|
|
|
{ |
|
101
|
|
|
foreach ($vars as $var_name) { |
|
102
|
|
|
if (isset($this->variables[$var_name])) { |
|
103
|
|
|
unset($this->variables[$var_name]); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|