1 | <?php |
||
18 | class View implements ViewInterface |
||
19 | { |
||
20 | /** Default view file extension */ |
||
21 | const DEFAULT_EXT = 'vphp'; |
||
22 | |||
23 | /** @var array Collection of $key => $value view data */ |
||
24 | protected $data = array(); |
||
25 | |||
26 | /** @var string Full path to view file */ |
||
27 | protected $file; |
||
28 | |||
29 | /** @var string View source code */ |
||
30 | protected $source; |
||
31 | |||
32 | /** @var string Rendered view contents */ |
||
33 | protected $output; |
||
34 | |||
35 | /** @var string Parent view block name */ |
||
36 | protected $parentBlock; |
||
37 | |||
38 | /** @var array Collection of view blocks */ |
||
39 | protected $blocks = array(); |
||
40 | |||
41 | /** @var array Blocks html list */ |
||
42 | protected $blocksHtml = array(); |
||
43 | |||
44 | /** |
||
45 | * Set current view for rendering. |
||
46 | * Method searches for the shortest matching view path by $pathPattern, |
||
47 | * from loaded views. |
||
48 | * |
||
49 | * Module saves all view data that has been set to a specific view in appropriate |
||
50 | * view data collection entry. By default module creates vied data entry - VD_POINTER_DEF, |
||
51 | * and until any call of iModule::view() or iModule::output(), all data that is iModule::set(), |
||
52 | * is stored to that location. |
||
53 | * |
||
54 | * On the first call of iModule::view() or iModule::output(), this method changes the view data |
||
55 | * pointer to actual relative view path, and copies(actually just sets view data pointer) all view |
||
56 | * data set before to new view data pointer. This guarantees backward compatibility and gives |
||
57 | * opportunity not to set the view path before setting view data to it. |
||
58 | * |
||
59 | * @param string $pathPattern Path pattern for view searching |
||
60 | * |
||
61 | * @return $this Chaining |
||
62 | * @throws \Exception |
||
63 | */ |
||
64 | 2 | public function view($pathPattern) |
|
73 | |||
74 | /** |
||
75 | * Render current view. |
||
76 | * Method uses current view context and outputs rendering |
||
77 | * result. |
||
78 | * |
||
79 | * @param bool $onlyCurrent Render only current view without extends |
||
80 | * @return string Rendered view |
||
81 | */ |
||
82 | 3 | public function output($onlyCurrent = false) |
|
89 | |||
90 | |||
91 | /** |
||
92 | * Render full views stack |
||
93 | * |
||
94 | * @param bool $onlyCurrent Render only current view without extends |
||
95 | * @return string Rendered view |
||
96 | */ |
||
97 | 3 | public function innerOutput($onlyCurrent = false ,$blocksList = array(), $data = array()) |
|
135 | |||
136 | /** |
||
137 | * Magic method for getting view variables. |
||
138 | * |
||
139 | * @param string $name Variable key |
||
140 | * |
||
141 | * @return mixed Value |
||
142 | * @throws VariableKeyNotFound |
||
143 | */ |
||
144 | 5 | public function __get($name) |
|
152 | |||
153 | /** |
||
154 | * Set current view parent rendering view and block. |
||
155 | * |
||
156 | * @param string $parent Fully qualified parent view name |
||
157 | * @param string $block View block for rendering in parent view |
||
158 | * |
||
159 | * @throws ViewClassNotFound |
||
160 | */ |
||
161 | 1 | public function extend($parent, $block) |
|
168 | |||
169 | /** |
||
170 | * Set current view nested block rendering view. |
||
171 | * |
||
172 | * @param string $blockName Nested view block container |
||
173 | */ |
||
174 | 1 | public function block($blockName) |
|
180 | |||
181 | /** |
||
182 | * Magic method for setting view variables. |
||
183 | * |
||
184 | * @param string $name Variable key |
||
185 | * @param array $arguments Variable value |
||
186 | * |
||
187 | * @return $this Chaining |
||
188 | * @throws VariableKeyNotFound |
||
189 | */ |
||
190 | 1 | public function __call($name, $arguments) |
|
198 | |||
199 | /** |
||
200 | * Set view variable. |
||
201 | * |
||
202 | * Passing an array as $value will add array key => values into current |
||
203 | * view data collection. If $key is passed then an array variable with this |
||
204 | * key will be added to view data collection beside adding array key => values. |
||
205 | * |
||
206 | * @param mixed $value Variable value |
||
207 | * @param string|null $key Variable key\prefix for objects and arrays |
||
208 | * |
||
209 | * @return $this Chaining |
||
210 | */ |
||
211 | 7 | public function set($value, $key = null) |
|
225 | |||
226 | |||
227 | /** |
||
228 | * Set renderable object as view variable. |
||
229 | * |
||
230 | * @param mixed $object Object instance for rendering |
||
231 | * @param string|null $key Variable key\prefix for objects and arrays |
||
232 | */ |
||
233 | 3 | protected function setRenderableObject($object, $key) |
|
242 | } |
||
243 |