1 | <?php |
||
17 | class View implements ViewInterface |
||
18 | { |
||
19 | /** Default view file extension */ |
||
20 | const DEFAULT_EXT = 'vphp'; |
||
21 | |||
22 | /** @deprecated Class name for old PHP versions */ |
||
23 | const CLASSNAME = __CLASS__; |
||
24 | |||
25 | /** @var array Collection of $key => $value view data */ |
||
26 | protected $data = array(); |
||
27 | |||
28 | /** @var string Full path to view file */ |
||
29 | protected $file; |
||
30 | |||
31 | /** @var string Rendered view contents */ |
||
32 | protected $output; |
||
33 | |||
34 | /** |
||
35 | * Set current view for rendering. |
||
36 | * Method searches for the shortest matching view path by $pathPattern, |
||
37 | * from loaded views. |
||
38 | * |
||
39 | * Module saves all view data that has been set to a specific view in appropriate |
||
40 | * view data collection entry. By default module creates vied data entry - VD_POINTER_DEF, |
||
41 | * and until any call of iModule::view() or iModule::output(), all data that is iModule::set(), |
||
42 | * is stored to that location. |
||
43 | * |
||
44 | * On the first call of iModule::view() or iModule::output(), this method changes the view data |
||
45 | * pointer to actual relative view path, and copies(actually just sets view data pointer) all view |
||
46 | * data set before to new view data pointer. This guarantees backward compatibility and gives |
||
47 | * opportunity not to set the view path before setting view data to it. |
||
48 | * |
||
49 | * @param string $pathPattern Path pattern for view searching |
||
50 | * |
||
51 | * @return $this Chaining |
||
52 | * @throws \Exception |
||
53 | */ |
||
54 | 2 | public function view($pathPattern) |
|
64 | |||
65 | /** |
||
66 | * Render current view. |
||
67 | * Method uses current view context and outputs rendering |
||
68 | * result. |
||
69 | * |
||
70 | * @return string Rendered view |
||
71 | */ |
||
72 | 1 | public function output() |
|
92 | |||
93 | /** |
||
94 | * Magic method for getting view variables. |
||
95 | * |
||
96 | * @param string $name Variable key |
||
97 | * |
||
98 | * @return mixed Value |
||
99 | * @throws VariableKeyNotFound |
||
100 | */ |
||
101 | 4 | public function __get($name) |
|
109 | |||
110 | /** |
||
111 | * Magic method for setting view variables. |
||
112 | * |
||
113 | * @param string $name Variable key |
||
114 | * @param array $arguments Variable value |
||
115 | * |
||
116 | * @return $this Chaining |
||
117 | * @throws VariableKeyNotFound |
||
118 | */ |
||
119 | 1 | public function __call($name, $arguments) |
|
127 | |||
128 | /** |
||
129 | * Set view variable. |
||
130 | * |
||
131 | * Passing an array as $value will add array key => values into current |
||
132 | * view data collection. If $key is passed then an array variable with this |
||
133 | * key will be added to view data collection beside adding array key => values. |
||
134 | * |
||
135 | * @param mixed $value Variable value |
||
136 | * @param string|null $key Variable key\prefix for objects and arrays |
||
137 | * |
||
138 | * @return $this Chaining |
||
139 | */ |
||
140 | 5 | public function set($value, $key = null) |
|
154 | |||
155 | /** |
||
156 | * Set renderable object as view variable. |
||
157 | * |
||
158 | * @param mixed $object Object instance for rendering |
||
159 | * @param string|null $key Variable key\prefix for objects and arrays |
||
160 | */ |
||
161 | 3 | protected function setRenderableObject($object, $key) |
|
170 | } |
||
171 |