1 | <?php declare(strict_types=1); |
||
33 | class ViewBuilder |
||
34 | { |
||
35 | |||
36 | use ConfigTrait; |
||
37 | |||
38 | const ENGINE_FINDER_KEY = 'EngineFinder'; |
||
39 | const VIEW_FINDER_KEY = 'ViewFinder'; |
||
40 | |||
41 | /** |
||
42 | * BaseViewFinder instance. |
||
43 | * |
||
44 | * @since 0.1.0 |
||
45 | * |
||
46 | * @var ViewFinder |
||
47 | */ |
||
48 | protected $viewFinder; |
||
49 | |||
50 | /** |
||
51 | * BaseEngineFinder instance. |
||
52 | * |
||
53 | * @since 0.1.0 |
||
54 | * |
||
55 | * @var EngineFinder |
||
56 | */ |
||
57 | protected $engineFinder; |
||
58 | |||
59 | /** |
||
60 | * Locations to scan for views. |
||
61 | * |
||
62 | * @since 0.1.0 |
||
63 | * |
||
64 | * @var Locations |
||
65 | */ |
||
66 | protected $locations; |
||
67 | |||
68 | /** |
||
69 | * Cache of already resolved view paths. |
||
70 | * |
||
71 | * @since 0.4.6 |
||
72 | * |
||
73 | * @var string[] |
||
74 | */ |
||
75 | protected $viewPathCache = []; |
||
76 | |||
77 | /** |
||
78 | * Instantiate a ViewBuilder object. |
||
79 | * |
||
80 | 16 | * @since 0.1.0 |
|
81 | * |
||
82 | * @param ConfigInterface $config Optional. Configuration settings. |
||
|
|||
83 | * @param ViewFinder|null $viewFinder Optional. ViewFinder instance. |
||
84 | * @param EngineFinder|null $engineFinder Optional. EngineFinder instance. |
||
85 | 16 | * |
|
86 | 16 | * @throws FailedToProcessConfigException If the config could not be processed. |
|
87 | 16 | */ |
|
88 | 16 | public function __construct( |
|
98 | |||
99 | /** |
||
100 | * Create a new view for a given URI. |
||
101 | 30 | * |
|
102 | * @since 0.1.0 |
||
103 | 30 | * |
|
104 | 30 | * @param string $view View identifier to create a view for. |
|
105 | * @param mixed $type Type of view to create. |
||
106 | 30 | * |
|
107 | 29 | * @return View Instance of the requested view. |
|
108 | 30 | * @throws FailedToInstantiateView If the view could not be instantiated. |
|
109 | */ |
||
110 | public function create(string $view, $type = null): View |
||
141 | |||
142 | 29 | /** |
|
143 | * Get an Engine that can deal with the given URI. |
||
144 | * |
||
145 | * @since 0.1.0 |
||
146 | * |
||
147 | * @param string $uri URI to get an engine for. |
||
148 | * |
||
149 | * @return Engine Instance of an engine that can deal with the given URI. |
||
150 | */ |
||
151 | public function getEngine(string $uri): Engine |
||
155 | |||
156 | /** |
||
157 | * Get a view for a given URI, engine and type. |
||
158 | * |
||
159 | * @since 0.1.0 |
||
160 | * |
||
161 | * @param string $uri URI to get a view for. |
||
162 | * @param Engine $engine Engine to use for the view. |
||
163 | * @param mixed $type Type of view to get. |
||
164 | 30 | * |
|
165 | * @return View View that matches the given requirements. |
||
166 | 30 | * @throws FailedToInstantiateView If the view could not be instantiated. |
|
167 | */ |
||
168 | public function getView(string $uri, Engine $engine, $type = null): View |
||
177 | |||
178 | 30 | /** |
|
179 | 30 | * Get the ViewFinder instance. |
|
180 | * |
||
181 | * @since 0.1.0 |
||
182 | * |
||
183 | * @return ViewFinder Instance of a BaseViewFinder. |
||
184 | */ |
||
185 | public function getViewFinder(): ViewFinder |
||
189 | |||
190 | /** |
||
191 | * Get the EngineFinder instance. |
||
192 | * |
||
193 | * @since 0.1.0 |
||
194 | * |
||
195 | * @return EngineFinder Instance of a BaseEngineFinder. |
||
196 | */ |
||
197 | public function getEngineFinder(): EngineFinder |
||
201 | |||
202 | 30 | /** |
|
203 | * Add a location to scan with the BaseViewFinder. |
||
204 | * |
||
205 | * @since 0.1.0 |
||
206 | 30 | * |
|
207 | 30 | * @param Location $location Location to scan with the BaseViewFinder. |
|
208 | 30 | * |
|
209 | 30 | * @return static |
|
210 | */ |
||
211 | 30 | public function addLocation(Location $location) |
|
220 | |||
221 | /** |
||
222 | * Get the collection of locations registered with this ViewBuilder. |
||
223 | * |
||
224 | 30 | * @since 0.1.3 |
|
225 | * |
||
226 | 30 | * @return Locations Collection of locations. |
|
227 | 30 | */ |
|
228 | 30 | public function getLocations() |
|
232 | |||
233 | /** |
||
234 | * Scan Locations for an URI that matches the specified criteria. |
||
235 | * |
||
236 | * @since 0.1.0 |
||
237 | * |
||
238 | * @param array $criteria Criteria to match. |
||
239 | * |
||
240 | * @return string|false URI of the requested view, or false if not found. |
||
241 | */ |
||
242 | public function scanLocations(array $criteria) |
||
262 | |||
263 | /** |
||
264 | * Get a finder instance. |
||
265 | * |
||
266 | * @since 0.1.1 |
||
267 | * |
||
268 | * @param string $key Configuration key to use. |
||
269 | * |
||
270 | * @return ViewFinder|EngineFinder The requested finder instance. |
||
271 | */ |
||
272 | protected function getFinder($key) |
||
277 | |||
278 | /** |
||
279 | * Resolve the view type. |
||
280 | * |
||
281 | * @since 0.1.0 |
||
282 | 16 | * |
|
283 | * @param mixed $type Type of view that was requested. |
||
284 | 16 | * @param string $uri URI to get a view for. |
|
285 | 16 | * @param Engine|null $engine Engine to use for the view. |
|
286 | 15 | * |
|
287 | 16 | * @return View Resolved View object. |
|
288 | * @throws FailedToInstantiateView If the view type could not be resolved. |
||
289 | 16 | */ |
|
290 | protected function resolveType($type, string $uri, Engine $engine = null): View |
||
318 | |||
319 | /** |
||
320 | * Get the configuration to use in the ViewBuilder. |
||
321 | * |
||
322 | * @since 0.2.0 |
||
323 | * |
||
324 | * @param ConfigInterface|array $config Config to merge with defaults. |
||
325 | * |
||
326 | * @return ConfigInterface Configuration passed in through the constructor. |
||
327 | */ |
||
328 | protected function getConfig($config = []): ConfigInterface |
||
337 | } |
||
338 |
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.
Most often this is a case of a parameter that can be null in addition to its declared types.