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 | * ViewFinder instance. |
||
44 | * |
||
45 | * @since 0.1.0 |
||
46 | * |
||
47 | * @var ViewFinderInterface |
||
48 | */ |
||
49 | protected $viewFinder; |
||
50 | |||
51 | /** |
||
52 | * EngineFinder instance. |
||
53 | * |
||
54 | * @since 0.1.0 |
||
55 | * |
||
56 | * @var EngineFinderInterface |
||
57 | */ |
||
58 | protected $engineFinder; |
||
59 | |||
60 | /** |
||
61 | * Locations to scan for views. |
||
62 | * |
||
63 | * @since 0.1.0 |
||
64 | * |
||
65 | * @var LocationCollection |
||
66 | */ |
||
67 | protected $locations; |
||
68 | |||
69 | /** |
||
70 | * Instantiate a ViewBuilder object. |
||
71 | * |
||
72 | * @since 0.1.0 |
||
73 | * |
||
74 | * @param ConfigInterface $config Configuration settings. |
||
75 | * @param ViewFinderInterface|null $viewFinder ViewFinder instance. |
||
76 | * @param EngineFinderInterface|null $engineFinder EngineFinder instance. |
||
77 | * |
||
78 | * @throws FailedToProcessConfigException If the config could not be processed. |
||
79 | */ |
||
80 | 10 | 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 ViewInterface Instance of the requested view. |
||
100 | */ |
||
101 | 24 | 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 EngineInterface Instance of an engine that can deal with the given URI. |
||
119 | */ |
||
120 | 24 | 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 EngineInterface $engine Engine to use for the view. |
||
132 | * @param mixed $type Type of view to get. |
||
133 | * |
||
134 | * @return ViewInterface View that matches the given requirements. |
||
135 | */ |
||
136 | 23 | public function getView($uri, EngineInterface $engine, $type = null) |
|
144 | |||
145 | /** |
||
146 | * Get the ViewFinder instance. |
||
147 | * |
||
148 | * @since 0.1.0 |
||
149 | * |
||
150 | * @return ViewFinderInterface Instance of a ViewFinder. |
||
151 | */ |
||
152 | 24 | public function getViewFinder() |
|
156 | |||
157 | /** |
||
158 | * Get the EngineFinder instance. |
||
159 | * |
||
160 | * @since 0.1.0 |
||
161 | * |
||
162 | * @return EngineFinderInterface Instance of a EngineFinder. |
||
163 | */ |
||
164 | 24 | public function getEngineFinder() |
|
168 | |||
169 | /** |
||
170 | * Add a location to scan with the ViewFinder. |
||
171 | * |
||
172 | * @since 0.1.0 |
||
173 | * |
||
174 | * @param LocationInterface $location Location to scan with the ViewFinder. |
||
175 | */ |
||
176 | 24 | public function addLocation(LocationInterface $location) |
|
180 | |||
181 | /** |
||
182 | * Get the collection of locations registered with this ViewBuilder. |
||
183 | * |
||
184 | * @since 0.1.3 |
||
185 | * |
||
186 | * @return LocationCollection 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 | 24 | 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 FinderInterface The requested finder instance. |
||
223 | */ |
||
224 | 24 | 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 EngineInterface|null $engine Engine to use for the view. |
||
242 | * |
||
243 | * @return ViewInterface Resolved View object. |
||
244 | * @throws FailedToInstantiateViewException If the view type could not be resolved. |
||
245 | */ |
||
246 | protected function resolveType($type, $uri, EngineInterface $engine = null) |
||
274 | } |
||
275 |