1 | <?php |
||
10 | class View |
||
11 | { |
||
12 | /** |
||
13 | * Active layout for view |
||
14 | * |
||
15 | * @var string|bool |
||
16 | */ |
||
17 | protected $layout; |
||
18 | |||
19 | /** |
||
20 | * Active module for view |
||
21 | * |
||
22 | * @var string|bool |
||
23 | */ |
||
24 | protected $module = false; |
||
25 | |||
26 | /** |
||
27 | * Rendered view content |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $view = false; |
||
32 | |||
33 | /** |
||
34 | * Data object for view |
||
35 | * |
||
36 | * @var object |
||
37 | */ |
||
38 | protected $properties; |
||
39 | |||
40 | /** |
||
41 | * \Zewa\Config reference |
||
42 | * |
||
43 | * @var Config |
||
44 | */ |
||
45 | protected $configuration; |
||
46 | |||
47 | /** |
||
48 | * \Zewa\Router reference |
||
49 | * |
||
50 | * @var Router |
||
51 | */ |
||
52 | protected $router; |
||
53 | |||
54 | /** |
||
55 | * \Zewa\Router reference |
||
56 | * |
||
57 | * @var Router |
||
58 | */ |
||
59 | protected $request; |
||
60 | |||
61 | /** |
||
62 | * @var array |
||
63 | */ |
||
64 | private $queuedJS = []; |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | private $queuedCSS = []; |
||
70 | |||
71 | /** |
||
72 | * Load up some basic configuration settings. |
||
73 | */ |
||
74 | public function __construct(Config $config, Router $router, Request $request) |
||
80 | |||
81 | /** |
||
82 | * Returns base URL for app |
||
83 | * @return string |
||
84 | */ |
||
85 | private function baseURL($path = '') |
||
89 | |||
90 | /** |
||
91 | * Returns the current request URL |
||
92 | * @return string |
||
93 | */ |
||
94 | private function currentURL($params = false) |
||
98 | |||
99 | /** |
||
100 | * Returns uri string |
||
101 | * @return string |
||
102 | */ |
||
103 | private function currentURI() |
||
107 | |||
108 | /* |
||
109 | * @todo create method for returning |
||
110 | * a valid json string with header.. |
||
111 | * view shouldn't set header logic, |
||
112 | * and the framework doesn't care what returns the string |
||
113 | * ..but view should handle the json_encode... |
||
114 | * seems overkill to call header() with returning a $view->json; |
||
115 | * thoughts?*/ |
||
116 | |||
117 | /** |
||
118 | * Loads a view |
||
119 | * |
||
120 | * @access public |
||
121 | * @param string|bool $view view to load |
||
122 | * @param string|bool $layout |
||
123 | * @return string |
||
124 | */ |
||
125 | public function render($view = false, $layout = false) |
||
154 | |||
155 | /** |
||
156 | * formats and prepares view for inclusion |
||
157 | * @param $viewName |
||
158 | * @return string |
||
159 | * @throws Exception\LookupException |
||
160 | */ |
||
161 | private function prepareView($viewName) |
||
184 | |||
185 | public function setView($viewName, $layout = false) |
||
192 | |||
193 | public function setProperty($property, $value = false) |
||
202 | |||
203 | public function setLayout($layout) |
||
219 | |||
220 | /** |
||
221 | * Set the module for view look |
||
222 | * |
||
223 | * @access public |
||
224 | * @param string|bool $module module to override |
||
225 | */ |
||
226 | public function setModule($module = false) |
||
235 | |||
236 | /** |
||
237 | * Processes view/layouts and exposes variables to the view/layout |
||
238 | * |
||
239 | * @access private |
||
240 | * @param string $file file being rendered |
||
241 | * @return string processed content |
||
242 | */ |
||
243 | //@TODO: come back and clean up this and the way the view receives stuff |
||
244 | private function process($file) |
||
261 | |||
262 | /** |
||
263 | * Helper method for grabbing aggregated css files |
||
264 | * |
||
265 | * @access protected |
||
266 | * @return string css includes |
||
267 | */ |
||
268 | protected function fetchCSS() |
||
282 | |||
283 | /** |
||
284 | * Helper method for grabbing aggregated JS files |
||
285 | * |
||
286 | * @access protected |
||
287 | * @return string JS includes |
||
288 | */ |
||
289 | protected function fetchJS() |
||
303 | |||
304 | /** |
||
305 | * Helper method for adding css files for aggregation/render |
||
306 | * |
||
307 | * @access public |
||
308 | * @param $files array |
||
309 | * @param $place string |
||
310 | * @return string css includes |
||
311 | * @throws Exception\LookupException |
||
312 | */ |
||
313 | public function addCSS($files = [], $place = 'append') |
||
321 | |||
322 | public function addJS($files = [], $place = 'append') |
||
330 | |||
331 | /** |
||
332 | * Set 404 header, and return 404 view contents |
||
333 | * |
||
334 | * @access public |
||
335 | * @param $data array |
||
336 | * @return string |
||
337 | */ |
||
338 | public function render404($data = []) |
||
345 | } |
||
346 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..