1 | <?php |
||
11 | class View |
||
12 | { |
||
13 | /** |
||
14 | * Active layout for view |
||
15 | * |
||
16 | * @var string|bool |
||
17 | */ |
||
18 | protected $layout; |
||
19 | |||
20 | private $pathToView; |
||
21 | |||
22 | private $pathToLayout; |
||
23 | |||
24 | /** @var array */ |
||
25 | protected $viewQueue; |
||
26 | |||
27 | /** |
||
28 | * Rendered view content |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $view = false; |
||
33 | |||
34 | /** |
||
35 | * Data object for view |
||
36 | * |
||
37 | * @var object |
||
38 | */ |
||
39 | protected $properties; |
||
40 | |||
41 | /** |
||
42 | * \Zewa\Config reference |
||
43 | * |
||
44 | * @var Config |
||
45 | */ |
||
46 | protected $configuration; |
||
47 | |||
48 | /** |
||
49 | * \Zewa\Router reference |
||
50 | * |
||
51 | * @var Router |
||
52 | */ |
||
53 | protected $router; |
||
54 | |||
55 | /** |
||
56 | * \Zewa\Router reference |
||
57 | * |
||
58 | * @var Router |
||
59 | */ |
||
60 | protected $request; |
||
61 | |||
62 | /** @var Container */ |
||
63 | protected $container; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | private $queuedJS = []; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | private $queuedCSS = []; |
||
74 | |||
75 | /** |
||
76 | * Load up some basic configuration settings. |
||
77 | */ |
||
78 | 11 | public function __construct(Config $config, Router $router, Request $request, Container $container) |
|
88 | |||
89 | /* |
||
90 | * @todo create method for returning |
||
91 | * a valid json string with header.. |
||
92 | * view shouldn't set header logic, |
||
93 | * and the framework doesn't care what returns the string |
||
94 | * ..but view should handle the json_encode... |
||
95 | * seems overkill to call header() with returning a $view->json; |
||
96 | * thoughts?*/ |
||
97 | |||
98 | /** |
||
99 | * Loads a view |
||
100 | * |
||
101 | * @access public |
||
102 | * @param string|bool $view view to load |
||
103 | * @param string|bool $layout |
||
104 | * @return string |
||
105 | */ |
||
106 | 6 | public function render($view = false, $layout = false) |
|
118 | |||
119 | /** |
||
120 | * formats and prepares view for inclusion |
||
121 | * @param $viewName |
||
122 | * @return string |
||
123 | * @throws Exception\LookupException |
||
124 | */ |
||
125 | 5 | public function setView($viewName) |
|
135 | |||
136 | 1 | public function getView($view = null) |
|
144 | |||
145 | 2 | public function setProperty($value, $primitive = null) |
|
157 | |||
158 | 1 | public function getProperty(string $key = null, $default = null) |
|
168 | |||
169 | 1 | public function unsetProperty(string $key) |
|
177 | |||
178 | 5 | public function setLayout($layout = null) |
|
195 | |||
196 | 1 | public function getLayout() |
|
200 | |||
201 | 4 | private function renderViews() : string |
|
212 | |||
213 | 4 | private function bufferResponse() : string |
|
223 | |||
224 | 4 | private function buffer(string $path) |
|
242 | |||
243 | /** |
||
244 | * Helper method for grabbing aggregated css files |
||
245 | * |
||
246 | * @access protected |
||
247 | * @return string css includes |
||
248 | */ |
||
249 | 2 | public function fetchCSS() |
|
263 | |||
264 | /** |
||
265 | * Helper method for grabbing aggregated JS files |
||
266 | * |
||
267 | * @access protected |
||
268 | * @return string JS includes |
||
269 | */ |
||
270 | 2 | public function fetchJS() |
|
284 | |||
285 | /** |
||
286 | * Helper method for adding css files for aggregation/render |
||
287 | * |
||
288 | * @access public |
||
289 | * @param $files array |
||
290 | * @param $append bool |
||
291 | */ |
||
292 | 1 | public function addCSS($files = []) |
|
296 | |||
297 | 1 | public function addJS($files = []) |
|
301 | |||
302 | /** |
||
303 | * Set 404 header, and return 404 view contents |
||
304 | * |
||
305 | * @access public |
||
306 | * @return string |
||
307 | */ |
||
308 | 1 | public function render404() |
|
314 | } |
||
315 |
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..