1 | <?php |
||
34 | class ViewBuilder |
||
35 | { |
||
36 | |||
37 | use ConfigTrait; |
||
38 | |||
39 | const ENGINE_FINDER_KEY = 'EngineFinder'; |
||
40 | const VIEW_FINDER_KEY = 'ViewFinder'; |
||
41 | |||
42 | /** |
||
43 | * BaseViewFinder instance. |
||
44 | * |
||
45 | * @since 0.1.0 |
||
46 | * |
||
47 | * @var ViewFinder |
||
48 | */ |
||
49 | protected $viewFinder; |
||
50 | |||
51 | /** |
||
52 | * BaseEngineFinder instance. |
||
53 | * |
||
54 | * @since 0.1.0 |
||
55 | * |
||
56 | * @var BaseEngineFinder |
||
57 | */ |
||
58 | protected $engineFinder; |
||
59 | |||
60 | /** |
||
61 | * Locations to scan for views. |
||
62 | * |
||
63 | * @since 0.1.0 |
||
64 | * |
||
65 | * @var Locations |
||
66 | */ |
||
67 | protected $locations; |
||
68 | |||
69 | /** |
||
70 | * Instantiate a ViewBuilder object. |
||
71 | * |
||
72 | * @since 0.1.0 |
||
73 | * |
||
74 | * @param ConfigInterface $config Optional. Configuration settings. |
||
|
|||
75 | * @param ViewFinder|null $viewFinder Optional. BaseViewFinder instance. |
||
76 | * @param BaseEngineFinder|null $engineFinder Optional. BaseEngineFinder instance. |
||
77 | * |
||
78 | * @throws FailedToProcessConfigException If the config could not be processed. |
||
79 | */ |
||
80 | 16 | public function __construct( |
|
90 | |||
91 | /** |
||
92 | * Create a new view for a given URI. |
||
93 | * |
||
94 | * @since 0.1.0 |
||
95 | * |
||
96 | * @param string $view View identifier to create a view for. |
||
97 | * @param mixed $type Type of view to create. |
||
98 | * |
||
99 | * @return View Instance of the requested view. |
||
100 | */ |
||
101 | 30 | public function create($view, $type = null) |
|
110 | |||
111 | /** |
||
112 | * Get an Engine that can deal with the given URI. |
||
113 | * |
||
114 | * @since 0.1.0 |
||
115 | * |
||
116 | * @param string|false $uri URI to get an engine for. |
||
117 | * |
||
118 | * @return Engine Instance of an engine that can deal with the given URI. |
||
119 | */ |
||
120 | 30 | public function getEngine($uri) |
|
124 | |||
125 | /** |
||
126 | * Get a view for a given URI, engine and type. |
||
127 | * |
||
128 | * @since 0.1.0 |
||
129 | * |
||
130 | * @param string $uri URI to get a view for. |
||
131 | * @param Engine $engine Engine to use for the view. |
||
132 | * @param mixed $type Type of view to get. |
||
133 | * |
||
134 | * @return View View that matches the given requirements. |
||
135 | */ |
||
136 | 29 | public function getView($uri, Engine $engine, $type = null) |
|
137 | { |
||
138 | 29 | $view = (null === $type) |
|
139 | 29 | ? $this->getViewFinder()->find([$uri], $engine) |
|
140 | 29 | : $this->resolveType($type, $uri, $engine); |
|
141 | |||
142 | 29 | return $view->setBuilder($this); |
|
143 | } |
||
144 | |||
145 | /** |
||
146 | * Get the BaseViewFinder instance. |
||
147 | * |
||
148 | * @since 0.1.0 |
||
149 | * |
||
150 | * @return ViewFinder Instance of a BaseViewFinder. |
||
151 | */ |
||
152 | 30 | public function getViewFinder() |
|
156 | |||
157 | /** |
||
158 | * Get the BaseEngineFinder instance. |
||
159 | * |
||
160 | * @since 0.1.0 |
||
161 | * |
||
162 | * @return BaseEngineFinder Instance of a BaseEngineFinder. |
||
163 | */ |
||
164 | 30 | public function getEngineFinder() |
|
168 | |||
169 | /** |
||
170 | * Add a location to scan with the BaseViewFinder. |
||
171 | * |
||
172 | * @since 0.1.0 |
||
173 | * |
||
174 | * @param Location $location Location to scan with the BaseViewFinder. |
||
175 | */ |
||
176 | 30 | public function addLocation(Location $location) |
|
180 | |||
181 | /** |
||
182 | * Get the collection of locations registered with this ViewBuilder. |
||
183 | * |
||
184 | * @since 0.1.3 |
||
185 | * |
||
186 | * @return Locations Collection of locations. |
||
187 | */ |
||
188 | public function getLocations() |
||
192 | |||
193 | /** |
||
194 | * Scan Locations for an URI that matches the specified criteria. |
||
195 | * |
||
196 | * @since 0.1.0 |
||
197 | * |
||
198 | * @param array $criteria Criteria to match. |
||
199 | * |
||
200 | * @return string|false URI of the requested view, or false if not found. |
||
201 | */ |
||
202 | 30 | public function scanLocations(array $criteria) |
|
213 | |||
214 | /** |
||
215 | * Get a finder instance. |
||
216 | * |
||
217 | * @since 0.1.1 |
||
218 | * |
||
219 | * @param mixed $property Property to use. |
||
220 | * @param string $key Configuration key to use. |
||
221 | * |
||
222 | * @return Finder The requested finder instance. |
||
223 | */ |
||
224 | 30 | protected function getFinder(&$property, $key) |
|
233 | |||
234 | /** |
||
235 | * Resolve the view type. |
||
236 | * |
||
237 | * @since 0.1.0 |
||
238 | * |
||
239 | * @param mixed $type Type of view that was requested. |
||
240 | * @param string $uri URI to get a view for. |
||
241 | * @param Engine|null $engine Engine to use for the view. |
||
242 | * |
||
243 | * @return View Resolved View object. |
||
244 | * @throws FailedToInstantiateView If the view type could not be resolved. |
||
245 | */ |
||
246 | protected function resolveType($type, $uri, Engine $engine = null) |
||
274 | |||
275 | /** |
||
276 | * Get the configuration to use in the ViewBuilder. |
||
277 | * |
||
278 | * @since 0.2.0 |
||
279 | * |
||
280 | * @return ConfigInterface Configuration passed in through the constructor. |
||
281 | */ |
||
282 | 16 | protected function getConfig($config = null) |
|
291 | } |
||
292 |
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.