1 | <?php declare(strict_types=1); |
||
30 | abstract class AbstractView implements View |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * URI of the view. |
||
35 | * |
||
36 | * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
||
37 | * |
||
38 | * @since 0.1.0 |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $_uri_; |
||
43 | |||
44 | /** |
||
45 | * Engine to use for the view. |
||
46 | * |
||
47 | * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
||
48 | * |
||
49 | * @since 0.1.0 |
||
50 | * |
||
51 | * @var Engine |
||
52 | */ |
||
53 | protected $_engine_; |
||
54 | |||
55 | /** |
||
56 | * ViewBuilder instance. |
||
57 | * |
||
58 | * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
||
59 | * |
||
60 | * @since 0.2.0 |
||
61 | * |
||
62 | * @var ViewBuilder |
||
63 | */ |
||
64 | protected $_builder_; |
||
65 | |||
66 | 29 | /** |
|
67 | * The context with which the view will be rendered. |
||
68 | 29 | * |
|
69 | 29 | * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
70 | 29 | * |
|
71 | * @since 0.4.0 |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $_context_ = []; |
||
76 | |||
77 | /** |
||
78 | * Instantiate an AbstractView object. |
||
79 | * |
||
80 | * @since 0.1.0 |
||
81 | * |
||
82 | 29 | * @param string $uri URI for the view. |
|
83 | * @param Engine $engine Engine to use for the view. |
||
84 | 29 | */ |
|
85 | 29 | public function __construct(string $uri, Engine $engine) |
|
90 | 29 | ||
91 | /** |
||
92 | * Render the view. |
||
93 | 29 | * |
|
94 | 29 | * @since 0.1.0 |
|
95 | * |
||
96 | * @param array $context Optional. The context in which to render the view. |
||
97 | * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
||
98 | * |
||
99 | * @return string Rendered HTML. |
||
100 | * @throws FailedToProcessConfigException If the Config could not be processed. |
||
101 | */ |
||
102 | public function render(array $context = [], bool $echo = false): string |
||
121 | |||
122 | /** |
||
123 | * Render a partial view (or section) for a given URI. |
||
124 | * |
||
125 | * @since 0.2.0 |
||
126 | * |
||
127 | * @param string $view View identifier to create a view for. |
||
128 | * @param array $context Optional. The context in which to render the view. |
||
|
|||
129 | * @param string|null $type Type of view to create. |
||
130 | * |
||
131 | * @return string Rendered HTML content. |
||
132 | 29 | * @throws FailedToProcessConfigException If the Config could not be processed. |
|
133 | * @throws FailedToInstantiateView If the View could not be instantiated. |
||
134 | 29 | */ |
|
135 | public function section(string $view, array $context = null, $type = null): string |
||
146 | 29 | ||
147 | /** |
||
148 | * Get the entire array of contextual data. |
||
149 | 29 | * |
|
150 | * @since 0.4.0 |
||
151 | * |
||
152 | * @return array Array of contextual data. |
||
153 | */ |
||
154 | public function getContext(): array |
||
158 | 29 | ||
159 | /** |
||
160 | 29 | * Associate a view builder with this view. |
|
161 | 29 | * |
|
162 | 29 | * @since 0.2.0 |
|
163 | * |
||
164 | 29 | * @param ViewBuilder $builder |
|
165 | * |
||
166 | * @return View |
||
167 | */ |
||
168 | public function setBuilder(ViewBuilder $builder): View |
||
174 | |||
175 | /** |
||
176 | * Initialize the view builder associated with the view. |
||
177 | * |
||
178 | * @since 0.2.0 |
||
179 | * |
||
180 | * @throws FailedToProcessConfigException If the Config could not be processed. |
||
181 | */ |
||
182 | protected function initializeViewBuilder() |
||
188 | |||
189 | /** |
||
190 | * Assimilate the context to make it available as properties. |
||
191 | * |
||
192 | * @since 0.2.0 |
||
193 | * |
||
194 | * @param array $context Context to assimilate. |
||
195 | */ |
||
196 | protected function assimilateContext(array $context = []) |
||
203 | } |
||
204 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
array
and suggests a stricter type likearray<String>
.Most often this is a case of a parameter that can be null in addition to its declared types.