1 | <?php |
||
17 | class View implements ViewInterface |
||
18 | { |
||
19 | /** Default view file extension */ |
||
20 | const DEFAULT_EXT = 'vphp'; |
||
21 | |||
22 | /** @var array Collection of $key => $value view data */ |
||
23 | protected $data = array(); |
||
24 | |||
25 | /** @var string Full path to view file */ |
||
26 | protected $file; |
||
27 | |||
28 | /** @var string View source code */ |
||
29 | protected $source; |
||
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) |
|
63 | |||
64 | /** |
||
65 | * Render current view. |
||
66 | * Method uses current view context and outputs rendering |
||
67 | * result. |
||
68 | * |
||
69 | * @return string Rendered view |
||
70 | */ |
||
71 | 1 | public function output() |
|
100 | |||
101 | /** |
||
102 | * Magic method for getting view variables. |
||
103 | * |
||
104 | * @param string $name Variable key |
||
105 | * |
||
106 | * @return mixed Value |
||
107 | * @throws VariableKeyNotFound |
||
108 | */ |
||
109 | 5 | public function __get($name) |
|
117 | |||
118 | /** |
||
119 | * Magic method for setting view variables. |
||
120 | * |
||
121 | * @param string $name Variable key |
||
122 | * @param array $arguments Variable value |
||
123 | * |
||
124 | * @return $this Chaining |
||
125 | * @throws VariableKeyNotFound |
||
126 | */ |
||
127 | 1 | public function __call($name, $arguments) |
|
135 | |||
136 | /** |
||
137 | * Set view variable. |
||
138 | * |
||
139 | * Passing an array as $value will add array key => values into current |
||
140 | * view data collection. If $key is passed then an array variable with this |
||
141 | * key will be added to view data collection beside adding array key => values. |
||
142 | * |
||
143 | * @param mixed $value Variable value |
||
144 | * @param string|null $key Variable key\prefix for objects and arrays |
||
145 | * |
||
146 | * @return $this Chaining |
||
147 | */ |
||
148 | 5 | public function set($value, $key = null) |
|
162 | |||
163 | /** |
||
164 | * Set renderable object as view variable. |
||
165 | * |
||
166 | * @param mixed $object Object instance for rendering |
||
167 | * @param string|null $key Variable key\prefix for objects and arrays |
||
168 | */ |
||
169 | 3 | protected function setRenderableObject($object, $key) |
|
178 | } |
||
179 |