1 | <?php declare(strict_types=1); |
||
19 | class View implements ViewInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $scriptRootPath = 'app/views'; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $fileExtension = 'html.php'; |
||
30 | |||
31 | /** |
||
32 | * Default helpers. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $helperClasses = [ |
||
37 | 'capturer' => Capturer::class, |
||
38 | 'mustacheTmplCapturer' => MustacheTmplCapturer::class, |
||
39 | 'pagination' => Pagination::class, |
||
40 | 'url' => Url::class, |
||
41 | 'inlineScriptCapturer' => InlineScriptCapturer::class, |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $helpers = []; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $variables = []; |
||
53 | |||
54 | /** |
||
55 | * @var string|null |
||
56 | */ |
||
57 | protected $layoutScript; |
||
58 | |||
59 | /** |
||
60 | * @var string|null |
||
61 | */ |
||
62 | protected $layoutContent; |
||
63 | |||
64 | /** |
||
65 | * @var Request |
||
66 | */ |
||
67 | private $request; |
||
68 | |||
69 | 15 | public function __construct(array $options = []) |
|
73 | |||
74 | 15 | public function setOptions(array $options): void |
|
84 | |||
85 | /** |
||
86 | * Magic method to set view variables. |
||
87 | * |
||
88 | * @param string $name |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | 4 | public function __set(string $name, $value): void |
|
95 | |||
96 | /** |
||
97 | * Magic method to get view variables. |
||
98 | * |
||
99 | * @param string $name |
||
100 | * @return mixed |
||
101 | */ |
||
102 | 2 | public function __get(string $name) |
|
110 | |||
111 | /** |
||
112 | * Magic method to test if view variable is set. |
||
113 | */ |
||
114 | 1 | public function __isset(string $name): bool |
|
118 | |||
119 | 1 | public function setLayout(string $script): void |
|
123 | |||
124 | /** |
||
125 | * Render output (returns) of the specified view script (with layout if that exists). |
||
126 | * |
||
127 | * @param string $script Relative script path (without file extension!). Eg. "some-script" or "admin/some-script". |
||
128 | * @param bool $renderLayout |
||
129 | * @return string |
||
130 | */ |
||
131 | 2 | public function render(string $script, bool $renderLayout = false): string |
|
142 | |||
143 | /** |
||
144 | * Internal method that does the actual script rendering. |
||
145 | */ |
||
146 | 3 | protected function renderScript(string $script): string |
|
160 | |||
161 | 2 | public function layoutContent(): string |
|
165 | |||
166 | /** |
||
167 | * Escape a string for output in view script. |
||
168 | */ |
||
169 | 2 | public function escape(?string $string, int $flags = \ENT_QUOTES): string |
|
173 | |||
174 | /** |
||
175 | * Returns view variable escaped for view script output. |
||
176 | */ |
||
177 | 1 | public function getEscaped(string $name): string |
|
185 | |||
186 | 2 | public function addHelperClass(string $helperName, string $className): void |
|
190 | |||
191 | 3 | public function getHelper(string $helperName): AbstractViewHelper |
|
206 | |||
207 | /** |
||
208 | * Magic method to call view helpers. |
||
209 | * If the helper has not defined __invoke(), the helper object will be returned. |
||
210 | * Otherwise, the result of the __invoke() is returned. |
||
211 | */ |
||
212 | 2 | public function __call(string $name, array $arguments = []) |
|
221 | |||
222 | 1 | public function setRequest(Request $request): void |
|
226 | |||
227 | 1 | public function getRequest(): Request |
|
231 | |||
232 | 1 | public function setLayoutContent(string $value): void |
|
236 | } |
||
237 |