@@ -51,7 +51,7 @@ |
||
51 | 51 | * @param string $uri URI to render. |
52 | 52 | * @param array $context Context in which to render. |
53 | 53 | * |
54 | - * @return callable Rendering callback. |
|
54 | + * @return \Closure Rendering callback. |
|
55 | 55 | * @throws FailedToLoadView If the View URI is not accessible or readable. |
56 | 56 | * @throws FailedToLoadView If the View URI could not be loaded. |
57 | 57 | */ |
@@ -26,75 +26,75 @@ |
||
26 | 26 | class PHPEngine extends AbstractEngine |
27 | 27 | { |
28 | 28 | |
29 | - const PHP_EXTENSION = '.php'; |
|
29 | + const PHP_EXTENSION = '.php'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Check whether the Findable can handle an individual criterion. |
|
33 | - * |
|
34 | - * @since 0.1.0 |
|
35 | - * |
|
36 | - * @param mixed $criterion Criterion to check. |
|
37 | - * |
|
38 | - * @return bool Whether the Findable can handle the criterion. |
|
39 | - */ |
|
40 | - public function canHandle($criterion): bool |
|
41 | - { |
|
42 | - return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) |
|
43 | - && is_readable($criterion); |
|
44 | - } |
|
31 | + /** |
|
32 | + * Check whether the Findable can handle an individual criterion. |
|
33 | + * |
|
34 | + * @since 0.1.0 |
|
35 | + * |
|
36 | + * @param mixed $criterion Criterion to check. |
|
37 | + * |
|
38 | + * @return bool Whether the Findable can handle the criterion. |
|
39 | + */ |
|
40 | + public function canHandle($criterion): bool |
|
41 | + { |
|
42 | + return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) |
|
43 | + && is_readable($criterion); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the rendering callback for a given URI. |
|
48 | - * |
|
49 | - * @since 0.1.0 |
|
50 | - * |
|
51 | - * @param string $uri URI to render. |
|
52 | - * @param array $context Context in which to render. |
|
53 | - * |
|
54 | - * @return callable Rendering callback. |
|
55 | - * @throws FailedToLoadView If the View URI is not accessible or readable. |
|
56 | - * @throws FailedToLoadView If the View URI could not be loaded. |
|
57 | - */ |
|
58 | - public function getRenderCallback(string $uri, array $context = []): callable |
|
59 | - { |
|
60 | - if (! is_readable($uri)) { |
|
61 | - throw new FailedToLoadView( |
|
62 | - sprintf( |
|
63 | - _('The View URI "%1$s" is not accessible or readable.'), |
|
64 | - $uri |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
46 | + /** |
|
47 | + * Get the rendering callback for a given URI. |
|
48 | + * |
|
49 | + * @since 0.1.0 |
|
50 | + * |
|
51 | + * @param string $uri URI to render. |
|
52 | + * @param array $context Context in which to render. |
|
53 | + * |
|
54 | + * @return callable Rendering callback. |
|
55 | + * @throws FailedToLoadView If the View URI is not accessible or readable. |
|
56 | + * @throws FailedToLoadView If the View URI could not be loaded. |
|
57 | + */ |
|
58 | + public function getRenderCallback(string $uri, array $context = []): callable |
|
59 | + { |
|
60 | + if (! is_readable($uri)) { |
|
61 | + throw new FailedToLoadView( |
|
62 | + sprintf( |
|
63 | + _('The View URI "%1$s" is not accessible or readable.'), |
|
64 | + $uri |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - $closure = function () use ($uri, $context) { |
|
69 | + $closure = function () use ($uri, $context) { |
|
70 | 70 | |
71 | - // Save current buffering level so we can backtrack in case of an error. |
|
72 | - // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
73 | - $bufferLevel = ob_get_level(); |
|
74 | - ob_start(); |
|
71 | + // Save current buffering level so we can backtrack in case of an error. |
|
72 | + // This is needed because the view itself might also add an unknown number of output buffering levels. |
|
73 | + $bufferLevel = ob_get_level(); |
|
74 | + ob_start(); |
|
75 | 75 | |
76 | - try { |
|
77 | - include $uri; |
|
78 | - } catch (Exception $exception) { |
|
79 | - // Remove whatever levels were added up until now. |
|
80 | - while (ob_get_level() > $bufferLevel) { |
|
81 | - ob_end_clean(); |
|
82 | - } |
|
76 | + try { |
|
77 | + include $uri; |
|
78 | + } catch (Exception $exception) { |
|
79 | + // Remove whatever levels were added up until now. |
|
80 | + while (ob_get_level() > $bufferLevel) { |
|
81 | + ob_end_clean(); |
|
82 | + } |
|
83 | 83 | |
84 | - throw new FailedToLoadView( |
|
85 | - sprintf( |
|
86 | - _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
87 | - $uri, |
|
88 | - $exception->getMessage() |
|
89 | - ), |
|
90 | - $exception->getCode(), |
|
91 | - $exception |
|
92 | - ); |
|
93 | - } |
|
84 | + throw new FailedToLoadView( |
|
85 | + sprintf( |
|
86 | + _('Could not load the View URI "%1$s". Reason: "%2$s".'), |
|
87 | + $uri, |
|
88 | + $exception->getMessage() |
|
89 | + ), |
|
90 | + $exception->getCode(), |
|
91 | + $exception |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | - return ob_get_clean(); |
|
96 | - }; |
|
95 | + return ob_get_clean(); |
|
96 | + }; |
|
97 | 97 | |
98 | - return $closure; |
|
99 | - } |
|
98 | + return $closure; |
|
99 | + } |
|
100 | 100 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function getRenderCallback(string $uri, array $context = []): callable |
59 | 59 | { |
60 | - if (! is_readable($uri)) { |
|
60 | + if ( ! is_readable($uri)) { |
|
61 | 61 | throw new FailedToLoadView( |
62 | 62 | sprintf( |
63 | 63 | _('The View URI "%1$s" is not accessible or readable.'), |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | ); |
67 | 67 | } |
68 | 68 | |
69 | - $closure = function () use ($uri, $context) { |
|
69 | + $closure = function() use ($uri, $context) { |
|
70 | 70 | |
71 | 71 | // Save current buffering level so we can backtrack in case of an error. |
72 | 72 | // This is needed because the view itself might also add an unknown number of output buffering levels. |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @since 0.1.0 |
95 | 95 | * |
96 | 96 | * @param string $view View identifier to create a view for. |
97 | - * @param mixed $type Type of view to create. |
|
97 | + * @param string|null $type Type of view to create. |
|
98 | 98 | * |
99 | 99 | * @return View Instance of the requested view. |
100 | 100 | * @throws FailedToInstantiateView If the view could not be instantiated. |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @since 0.1.0 |
201 | 201 | * |
202 | - * @param array $criteria Criteria to match. |
|
202 | + * @param string[] $criteria Criteria to match. |
|
203 | 203 | * |
204 | 204 | * @return string|false URI of the requested view, or false if not found. |
205 | 205 | */ |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @since 0.2.0 |
283 | 283 | * |
284 | - * @param ConfigInterface|array $config Config to merge with defaults. |
|
284 | + * @param null|ConfigInterface $config Config to merge with defaults. |
|
285 | 285 | * |
286 | 286 | * @return ConfigInterface Configuration passed in through the constructor. |
287 | 287 | */ |
@@ -33,274 +33,274 @@ |
||
33 | 33 | class ViewBuilder |
34 | 34 | { |
35 | 35 | |
36 | - use ConfigTrait; |
|
36 | + use ConfigTrait; |
|
37 | 37 | |
38 | - const ENGINE_FINDER_KEY = 'EngineFinder'; |
|
39 | - const VIEW_FINDER_KEY = 'ViewFinder'; |
|
38 | + const ENGINE_FINDER_KEY = 'EngineFinder'; |
|
39 | + const VIEW_FINDER_KEY = 'ViewFinder'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * BaseViewFinder instance. |
|
43 | - * |
|
44 | - * @since 0.1.0 |
|
45 | - * |
|
46 | - * @var ViewFinder |
|
47 | - */ |
|
48 | - protected $viewFinder; |
|
41 | + /** |
|
42 | + * BaseViewFinder instance. |
|
43 | + * |
|
44 | + * @since 0.1.0 |
|
45 | + * |
|
46 | + * @var ViewFinder |
|
47 | + */ |
|
48 | + protected $viewFinder; |
|
49 | 49 | |
50 | - /** |
|
51 | - * BaseEngineFinder instance. |
|
52 | - * |
|
53 | - * @since 0.1.0 |
|
54 | - * |
|
55 | - * @var EngineFinder |
|
56 | - */ |
|
57 | - protected $engineFinder; |
|
50 | + /** |
|
51 | + * BaseEngineFinder instance. |
|
52 | + * |
|
53 | + * @since 0.1.0 |
|
54 | + * |
|
55 | + * @var EngineFinder |
|
56 | + */ |
|
57 | + protected $engineFinder; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Locations to scan for views. |
|
61 | - * |
|
62 | - * @since 0.1.0 |
|
63 | - * |
|
64 | - * @var Locations |
|
65 | - */ |
|
66 | - protected $locations; |
|
59 | + /** |
|
60 | + * Locations to scan for views. |
|
61 | + * |
|
62 | + * @since 0.1.0 |
|
63 | + * |
|
64 | + * @var Locations |
|
65 | + */ |
|
66 | + protected $locations; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Instantiate a ViewBuilder object. |
|
70 | - * |
|
71 | - * @since 0.1.0 |
|
72 | - * |
|
73 | - * @param ConfigInterface $config Optional. Configuration settings. |
|
74 | - * @param ViewFinder|null $viewFinder Optional. ViewFinder instance. |
|
75 | - * @param EngineFinder|null $engineFinder Optional. EngineFinder instance. |
|
76 | - * |
|
77 | - * @throws FailedToProcessConfigException If the config could not be processed. |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - ConfigInterface $config = null, |
|
81 | - ViewFinder $viewFinder = null, |
|
82 | - EngineFinder $engineFinder = null |
|
83 | - ) { |
|
84 | - $this->processConfig($this->getConfig($config)); |
|
85 | - $this->viewFinder = $viewFinder ?? $this->getViewFinder(); |
|
86 | - $this->engineFinder = $engineFinder ?? $this->getEngineFinder(); |
|
87 | - $this->locations = new Locations(); |
|
88 | - } |
|
68 | + /** |
|
69 | + * Instantiate a ViewBuilder object. |
|
70 | + * |
|
71 | + * @since 0.1.0 |
|
72 | + * |
|
73 | + * @param ConfigInterface $config Optional. Configuration settings. |
|
74 | + * @param ViewFinder|null $viewFinder Optional. ViewFinder instance. |
|
75 | + * @param EngineFinder|null $engineFinder Optional. EngineFinder instance. |
|
76 | + * |
|
77 | + * @throws FailedToProcessConfigException If the config could not be processed. |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + ConfigInterface $config = null, |
|
81 | + ViewFinder $viewFinder = null, |
|
82 | + EngineFinder $engineFinder = null |
|
83 | + ) { |
|
84 | + $this->processConfig($this->getConfig($config)); |
|
85 | + $this->viewFinder = $viewFinder ?? $this->getViewFinder(); |
|
86 | + $this->engineFinder = $engineFinder ?? $this->getEngineFinder(); |
|
87 | + $this->locations = new Locations(); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Create a new view for a given URI. |
|
92 | - * |
|
93 | - * @since 0.1.0 |
|
94 | - * |
|
95 | - * @param string $view View identifier to create a view for. |
|
96 | - * @param mixed $type Type of view to create. |
|
97 | - * |
|
98 | - * @return View Instance of the requested view. |
|
99 | - * @throws FailedToInstantiateView If the view could not be instantiated. |
|
100 | - */ |
|
101 | - public function create(string $view, $type = null): View |
|
102 | - { |
|
103 | - $uri = $this->scanLocations([$view]); |
|
90 | + /** |
|
91 | + * Create a new view for a given URI. |
|
92 | + * |
|
93 | + * @since 0.1.0 |
|
94 | + * |
|
95 | + * @param string $view View identifier to create a view for. |
|
96 | + * @param mixed $type Type of view to create. |
|
97 | + * |
|
98 | + * @return View Instance of the requested view. |
|
99 | + * @throws FailedToInstantiateView If the view could not be instantiated. |
|
100 | + */ |
|
101 | + public function create(string $view, $type = null): View |
|
102 | + { |
|
103 | + $uri = $this->scanLocations([$view]); |
|
104 | 104 | |
105 | - $engine = $uri |
|
106 | - ? $this->getEngine($uri) |
|
107 | - : false; |
|
105 | + $engine = $uri |
|
106 | + ? $this->getEngine($uri) |
|
107 | + : false; |
|
108 | 108 | |
109 | - return ($uri && $engine) |
|
110 | - ? $this->getView($uri, $engine, $type) |
|
111 | - : $this->getViewFinder()->getNullObject(); |
|
112 | - } |
|
109 | + return ($uri && $engine) |
|
110 | + ? $this->getView($uri, $engine, $type) |
|
111 | + : $this->getViewFinder()->getNullObject(); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Get an Engine that can deal with the given URI. |
|
116 | - * |
|
117 | - * @since 0.1.0 |
|
118 | - * |
|
119 | - * @param string $uri URI to get an engine for. |
|
120 | - * |
|
121 | - * @return Engine Instance of an engine that can deal with the given URI. |
|
122 | - */ |
|
123 | - public function getEngine(string $uri): Engine |
|
124 | - { |
|
125 | - return $this->getEngineFinder()->find([$uri]); |
|
126 | - } |
|
114 | + /** |
|
115 | + * Get an Engine that can deal with the given URI. |
|
116 | + * |
|
117 | + * @since 0.1.0 |
|
118 | + * |
|
119 | + * @param string $uri URI to get an engine for. |
|
120 | + * |
|
121 | + * @return Engine Instance of an engine that can deal with the given URI. |
|
122 | + */ |
|
123 | + public function getEngine(string $uri): Engine |
|
124 | + { |
|
125 | + return $this->getEngineFinder()->find([$uri]); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get a view for a given URI, engine and type. |
|
130 | - * |
|
131 | - * @since 0.1.0 |
|
132 | - * |
|
133 | - * @param string $uri URI to get a view for. |
|
134 | - * @param Engine $engine Engine to use for the view. |
|
135 | - * @param mixed $type Type of view to get. |
|
136 | - * |
|
137 | - * @return View View that matches the given requirements. |
|
138 | - * @throws FailedToInstantiateView If the view could not be instantiated. |
|
139 | - */ |
|
140 | - public function getView(string $uri, Engine $engine, $type = null): View |
|
141 | - { |
|
142 | - if (null === $type) { |
|
143 | - $view = $this->getViewFinder()->find([$uri], $engine); |
|
144 | - return $view->setBuilder( $this ); |
|
145 | - } |
|
128 | + /** |
|
129 | + * Get a view for a given URI, engine and type. |
|
130 | + * |
|
131 | + * @since 0.1.0 |
|
132 | + * |
|
133 | + * @param string $uri URI to get a view for. |
|
134 | + * @param Engine $engine Engine to use for the view. |
|
135 | + * @param mixed $type Type of view to get. |
|
136 | + * |
|
137 | + * @return View View that matches the given requirements. |
|
138 | + * @throws FailedToInstantiateView If the view could not be instantiated. |
|
139 | + */ |
|
140 | + public function getView(string $uri, Engine $engine, $type = null): View |
|
141 | + { |
|
142 | + if (null === $type) { |
|
143 | + $view = $this->getViewFinder()->find([$uri], $engine); |
|
144 | + return $view->setBuilder( $this ); |
|
145 | + } |
|
146 | 146 | |
147 | - return $this->resolveType($type, $uri, $engine); |
|
148 | - } |
|
147 | + return $this->resolveType($type, $uri, $engine); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Get the ViewFinder instance. |
|
152 | - * |
|
153 | - * @since 0.1.0 |
|
154 | - * |
|
155 | - * @return ViewFinder Instance of a BaseViewFinder. |
|
156 | - */ |
|
157 | - public function getViewFinder(): ViewFinder |
|
158 | - { |
|
159 | - return $this->viewFinder ?? $this->getFinder(static::VIEW_FINDER_KEY); |
|
160 | - } |
|
150 | + /** |
|
151 | + * Get the ViewFinder instance. |
|
152 | + * |
|
153 | + * @since 0.1.0 |
|
154 | + * |
|
155 | + * @return ViewFinder Instance of a BaseViewFinder. |
|
156 | + */ |
|
157 | + public function getViewFinder(): ViewFinder |
|
158 | + { |
|
159 | + return $this->viewFinder ?? $this->getFinder(static::VIEW_FINDER_KEY); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Get the EngineFinder instance. |
|
164 | - * |
|
165 | - * @since 0.1.0 |
|
166 | - * |
|
167 | - * @return EngineFinder Instance of a BaseEngineFinder. |
|
168 | - */ |
|
169 | - public function getEngineFinder(): EngineFinder |
|
170 | - { |
|
171 | - return $this->engineFinder ?? $this->getFinder(static::ENGINE_FINDER_KEY); |
|
172 | - } |
|
162 | + /** |
|
163 | + * Get the EngineFinder instance. |
|
164 | + * |
|
165 | + * @since 0.1.0 |
|
166 | + * |
|
167 | + * @return EngineFinder Instance of a BaseEngineFinder. |
|
168 | + */ |
|
169 | + public function getEngineFinder(): EngineFinder |
|
170 | + { |
|
171 | + return $this->engineFinder ?? $this->getFinder(static::ENGINE_FINDER_KEY); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Add a location to scan with the BaseViewFinder. |
|
176 | - * |
|
177 | - * @since 0.1.0 |
|
178 | - * |
|
179 | - * @param Location $location Location to scan with the BaseViewFinder. |
|
180 | - * |
|
181 | - * @return static |
|
182 | - */ |
|
183 | - public function addLocation(Location $location) |
|
184 | - { |
|
185 | - $this->locations->add($location); |
|
174 | + /** |
|
175 | + * Add a location to scan with the BaseViewFinder. |
|
176 | + * |
|
177 | + * @since 0.1.0 |
|
178 | + * |
|
179 | + * @param Location $location Location to scan with the BaseViewFinder. |
|
180 | + * |
|
181 | + * @return static |
|
182 | + */ |
|
183 | + public function addLocation(Location $location) |
|
184 | + { |
|
185 | + $this->locations->add($location); |
|
186 | 186 | |
187 | - return $this; |
|
188 | - } |
|
187 | + return $this; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Get the collection of locations registered with this ViewBuilder. |
|
192 | - * |
|
193 | - * @since 0.1.3 |
|
194 | - * |
|
195 | - * @return Locations Collection of locations. |
|
196 | - */ |
|
197 | - public function getLocations() |
|
198 | - { |
|
199 | - return $this->locations; |
|
200 | - } |
|
190 | + /** |
|
191 | + * Get the collection of locations registered with this ViewBuilder. |
|
192 | + * |
|
193 | + * @since 0.1.3 |
|
194 | + * |
|
195 | + * @return Locations Collection of locations. |
|
196 | + */ |
|
197 | + public function getLocations() |
|
198 | + { |
|
199 | + return $this->locations; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Scan Locations for an URI that matches the specified criteria. |
|
204 | - * |
|
205 | - * @since 0.1.0 |
|
206 | - * |
|
207 | - * @param array $criteria Criteria to match. |
|
208 | - * |
|
209 | - * @return string|false URI of the requested view, or false if not found. |
|
210 | - */ |
|
211 | - public function scanLocations(array $criteria) |
|
212 | - { |
|
213 | - $uris = $this->locations->map(function ($location) use ($criteria) { |
|
214 | - /** @var Location $location */ |
|
215 | - return $location->getURI($criteria); |
|
216 | - })->filter(function ($uri) { |
|
217 | - return false !== $uri; |
|
218 | - }); |
|
202 | + /** |
|
203 | + * Scan Locations for an URI that matches the specified criteria. |
|
204 | + * |
|
205 | + * @since 0.1.0 |
|
206 | + * |
|
207 | + * @param array $criteria Criteria to match. |
|
208 | + * |
|
209 | + * @return string|false URI of the requested view, or false if not found. |
|
210 | + */ |
|
211 | + public function scanLocations(array $criteria) |
|
212 | + { |
|
213 | + $uris = $this->locations->map(function ($location) use ($criteria) { |
|
214 | + /** @var Location $location */ |
|
215 | + return $location->getURI($criteria); |
|
216 | + })->filter(function ($uri) { |
|
217 | + return false !== $uri; |
|
218 | + }); |
|
219 | 219 | |
220 | - // Fall back for absolute paths on current filesystem. |
|
221 | - if ($uris->isEmpty()) { |
|
222 | - foreach ($criteria as $criterion) { |
|
223 | - if (file_exists($criterion)) { |
|
224 | - return $criterion; |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
220 | + // Fall back for absolute paths on current filesystem. |
|
221 | + if ($uris->isEmpty()) { |
|
222 | + foreach ($criteria as $criterion) { |
|
223 | + if (file_exists($criterion)) { |
|
224 | + return $criterion; |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - return $uris->isEmpty() ? false : $uris->first(); |
|
230 | - } |
|
229 | + return $uris->isEmpty() ? false : $uris->first(); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Get a finder instance. |
|
234 | - * |
|
235 | - * @since 0.1.1 |
|
236 | - * |
|
237 | - * @param string $key Configuration key to use. |
|
238 | - * |
|
239 | - * @return ViewFinder|EngineFinder The requested finder instance. |
|
240 | - */ |
|
241 | - protected function getFinder($key) |
|
242 | - { |
|
243 | - $finderClass = $this->config->getKey($key, 'ClassName'); |
|
244 | - return new $finderClass($this->config->getSubConfig($key)); |
|
245 | - } |
|
232 | + /** |
|
233 | + * Get a finder instance. |
|
234 | + * |
|
235 | + * @since 0.1.1 |
|
236 | + * |
|
237 | + * @param string $key Configuration key to use. |
|
238 | + * |
|
239 | + * @return ViewFinder|EngineFinder The requested finder instance. |
|
240 | + */ |
|
241 | + protected function getFinder($key) |
|
242 | + { |
|
243 | + $finderClass = $this->config->getKey($key, 'ClassName'); |
|
244 | + return new $finderClass($this->config->getSubConfig($key)); |
|
245 | + } |
|
246 | 246 | |
247 | - /** |
|
248 | - * Resolve the view type. |
|
249 | - * |
|
250 | - * @since 0.1.0 |
|
251 | - * |
|
252 | - * @param mixed $type Type of view that was requested. |
|
253 | - * @param string $uri URI to get a view for. |
|
254 | - * @param Engine|null $engine Engine to use for the view. |
|
255 | - * |
|
256 | - * @return View Resolved View object. |
|
257 | - * @throws FailedToInstantiateView If the view type could not be resolved. |
|
258 | - */ |
|
259 | - protected function resolveType($type, string $uri, Engine $engine = null): View |
|
260 | - { |
|
261 | - $configKey = [static::VIEW_FINDER_KEY, 'Views', $type]; |
|
247 | + /** |
|
248 | + * Resolve the view type. |
|
249 | + * |
|
250 | + * @since 0.1.0 |
|
251 | + * |
|
252 | + * @param mixed $type Type of view that was requested. |
|
253 | + * @param string $uri URI to get a view for. |
|
254 | + * @param Engine|null $engine Engine to use for the view. |
|
255 | + * |
|
256 | + * @return View Resolved View object. |
|
257 | + * @throws FailedToInstantiateView If the view type could not be resolved. |
|
258 | + */ |
|
259 | + protected function resolveType($type, string $uri, Engine $engine = null): View |
|
260 | + { |
|
261 | + $configKey = [static::VIEW_FINDER_KEY, 'Views', $type]; |
|
262 | 262 | |
263 | - if (is_string($type) && $this->config->hasKey($configKey)) { |
|
264 | - $className = $this->config->getKey($configKey); |
|
265 | - $type = new $className($uri, $engine, $this); |
|
266 | - } |
|
263 | + if (is_string($type) && $this->config->hasKey($configKey)) { |
|
264 | + $className = $this->config->getKey($configKey); |
|
265 | + $type = new $className($uri, $engine, $this); |
|
266 | + } |
|
267 | 267 | |
268 | - if (is_string($type)) { |
|
269 | - $type = new $type($uri, $engine, $this); |
|
270 | - } |
|
268 | + if (is_string($type)) { |
|
269 | + $type = new $type($uri, $engine, $this); |
|
270 | + } |
|
271 | 271 | |
272 | - if (is_callable($type)) { |
|
273 | - $type = $type($uri, $engine, $this); |
|
274 | - } |
|
272 | + if (is_callable($type)) { |
|
273 | + $type = $type($uri, $engine, $this); |
|
274 | + } |
|
275 | 275 | |
276 | - if (! $type instanceof View) { |
|
277 | - throw new FailedToInstantiateView( |
|
278 | - sprintf( |
|
279 | - _('Could not instantiate view "%s".'), |
|
280 | - serialize($type) |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
276 | + if (! $type instanceof View) { |
|
277 | + throw new FailedToInstantiateView( |
|
278 | + sprintf( |
|
279 | + _('Could not instantiate view "%s".'), |
|
280 | + serialize($type) |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | |
285 | - return $type; |
|
286 | - } |
|
285 | + return $type; |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * Get the configuration to use in the ViewBuilder. |
|
290 | - * |
|
291 | - * @since 0.2.0 |
|
292 | - * |
|
293 | - * @param ConfigInterface|array $config Config to merge with defaults. |
|
294 | - * |
|
295 | - * @return ConfigInterface Configuration passed in through the constructor. |
|
296 | - */ |
|
297 | - protected function getConfig($config = []): ConfigInterface |
|
298 | - { |
|
299 | - $defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config); |
|
300 | - $config = $config |
|
301 | - ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) |
|
302 | - : $defaults; |
|
288 | + /** |
|
289 | + * Get the configuration to use in the ViewBuilder. |
|
290 | + * |
|
291 | + * @since 0.2.0 |
|
292 | + * |
|
293 | + * @param ConfigInterface|array $config Config to merge with defaults. |
|
294 | + * |
|
295 | + * @return ConfigInterface Configuration passed in through the constructor. |
|
296 | + */ |
|
297 | + protected function getConfig($config = []): ConfigInterface |
|
298 | + { |
|
299 | + $defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config); |
|
300 | + $config = $config |
|
301 | + ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) |
|
302 | + : $defaults; |
|
303 | 303 | |
304 | - return $config->getSubConfig('BrightNucleus\View'); |
|
305 | - } |
|
304 | + return $config->getSubConfig('BrightNucleus\View'); |
|
305 | + } |
|
306 | 306 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | if (null === $type) { |
143 | 143 | $view = $this->getViewFinder()->find([$uri], $engine); |
144 | - return $view->setBuilder( $this ); |
|
144 | + return $view->setBuilder($this); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | return $this->resolveType($type, $uri, $engine); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function scanLocations(array $criteria) |
212 | 212 | { |
213 | - $uris = $this->locations->map(function ($location) use ($criteria) { |
|
213 | + $uris = $this->locations->map(function($location) use ($criteria) { |
|
214 | 214 | /** @var Location $location */ |
215 | 215 | return $location->getURI($criteria); |
216 | - })->filter(function ($uri) { |
|
216 | + })->filter(function($uri) { |
|
217 | 217 | return false !== $uri; |
218 | 218 | }); |
219 | 219 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $type = $type($uri, $engine, $this); |
274 | 274 | } |
275 | 275 | |
276 | - if (! $type instanceof View) { |
|
276 | + if ( ! $type instanceof View) { |
|
277 | 277 | throw new FailedToInstantiateView( |
278 | 278 | sprintf( |
279 | 279 | _('Could not instantiate view "%s".'), |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getConfig($config = []): ConfigInterface |
298 | 298 | { |
299 | - $defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config); |
|
299 | + $defaults = ConfigFactory::create(dirname(__DIR__, 2).'/config/defaults.php', $config); |
|
300 | 300 | $config = $config |
301 | 301 | ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) |
302 | 302 | : $defaults; |
@@ -28,97 +28,97 @@ |
||
28 | 28 | class Views |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * ViewBuilder Instance. |
|
33 | - * |
|
34 | - * @since 0.1.0 |
|
35 | - * |
|
36 | - * @var ViewBuilder |
|
37 | - */ |
|
38 | - protected static $viewBuilder; |
|
31 | + /** |
|
32 | + * ViewBuilder Instance. |
|
33 | + * |
|
34 | + * @since 0.1.0 |
|
35 | + * |
|
36 | + * @var ViewBuilder |
|
37 | + */ |
|
38 | + protected static $viewBuilder; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Add a location to the ViewBuilder. |
|
42 | - * |
|
43 | - * @since 0.1.0 |
|
44 | - * |
|
45 | - * @param Location $location Location to add. |
|
46 | - * |
|
47 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
48 | - */ |
|
49 | - public static function addLocation(Location $location) |
|
50 | - { |
|
51 | - $viewBuilder = static::getViewBuilder(); |
|
52 | - $viewBuilder->addLocation($location); |
|
53 | - } |
|
40 | + /** |
|
41 | + * Add a location to the ViewBuilder. |
|
42 | + * |
|
43 | + * @since 0.1.0 |
|
44 | + * |
|
45 | + * @param Location $location Location to add. |
|
46 | + * |
|
47 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
48 | + */ |
|
49 | + public static function addLocation(Location $location) |
|
50 | + { |
|
51 | + $viewBuilder = static::getViewBuilder(); |
|
52 | + $viewBuilder->addLocation($location); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the ViewBuilder instance. |
|
57 | - * |
|
58 | - * @since 0.1.0 |
|
59 | - * |
|
60 | - * @return ViewBuilder |
|
61 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
62 | - */ |
|
63 | - public static function getViewBuilder() |
|
64 | - { |
|
65 | - if (null === static::$viewBuilder) { |
|
66 | - static::$viewBuilder = static::instantiateViewBuilder(); |
|
67 | - } |
|
55 | + /** |
|
56 | + * Get the ViewBuilder instance. |
|
57 | + * |
|
58 | + * @since 0.1.0 |
|
59 | + * |
|
60 | + * @return ViewBuilder |
|
61 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
62 | + */ |
|
63 | + public static function getViewBuilder() |
|
64 | + { |
|
65 | + if (null === static::$viewBuilder) { |
|
66 | + static::$viewBuilder = static::instantiateViewBuilder(); |
|
67 | + } |
|
68 | 68 | |
69 | - return static::$viewBuilder; |
|
70 | - } |
|
69 | + return static::$viewBuilder; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Instantiate the ViewBuilder. |
|
74 | - * |
|
75 | - * @since 0.1.0 |
|
76 | - * |
|
77 | - * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
78 | - * |
|
79 | - * @return ViewBuilder Instance of the ViewBuilder. |
|
80 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
81 | - */ |
|
82 | - public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
83 | - { |
|
84 | - return static::$viewBuilder = new ViewBuilder($config); |
|
85 | - } |
|
72 | + /** |
|
73 | + * Instantiate the ViewBuilder. |
|
74 | + * |
|
75 | + * @since 0.1.0 |
|
76 | + * |
|
77 | + * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
78 | + * |
|
79 | + * @return ViewBuilder Instance of the ViewBuilder. |
|
80 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
81 | + */ |
|
82 | + public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
83 | + { |
|
84 | + return static::$viewBuilder = new ViewBuilder($config); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Create a new view for a given URI. |
|
89 | - * |
|
90 | - * @since 0.1.0 |
|
91 | - * |
|
92 | - * @param string $view View identifier to create a view for. |
|
93 | - * @param string|null $type Type of view to create. |
|
94 | - * |
|
95 | - * @return View Instance of the requested view. |
|
96 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
97 | - */ |
|
98 | - public static function create($view, $type = null) |
|
99 | - { |
|
100 | - $viewBuilder = static::getViewBuilder(); |
|
87 | + /** |
|
88 | + * Create a new view for a given URI. |
|
89 | + * |
|
90 | + * @since 0.1.0 |
|
91 | + * |
|
92 | + * @param string $view View identifier to create a view for. |
|
93 | + * @param string|null $type Type of view to create. |
|
94 | + * |
|
95 | + * @return View Instance of the requested view. |
|
96 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
97 | + */ |
|
98 | + public static function create($view, $type = null) |
|
99 | + { |
|
100 | + $viewBuilder = static::getViewBuilder(); |
|
101 | 101 | |
102 | - return $viewBuilder->create($view, $type); |
|
103 | - } |
|
102 | + return $viewBuilder->create($view, $type); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Render a view for a given URI. |
|
107 | - * |
|
108 | - * @since 0.1.0 |
|
109 | - * |
|
110 | - * @param string $view View identifier to create a view for. |
|
111 | - * @param array $context Optional. The context in which to render the view. |
|
112 | - * @param string|null $type Type of view to create. |
|
113 | - * |
|
114 | - * @return string Rendered HTML content. |
|
115 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
116 | - */ |
|
117 | - public static function render($view, array $context = [], $type = null) |
|
118 | - { |
|
119 | - $viewBuilder = static::getViewBuilder(); |
|
120 | - $viewObject = $viewBuilder->create($view, $type); |
|
105 | + /** |
|
106 | + * Render a view for a given URI. |
|
107 | + * |
|
108 | + * @since 0.1.0 |
|
109 | + * |
|
110 | + * @param string $view View identifier to create a view for. |
|
111 | + * @param array $context Optional. The context in which to render the view. |
|
112 | + * @param string|null $type Type of view to create. |
|
113 | + * |
|
114 | + * @return string Rendered HTML content. |
|
115 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
116 | + */ |
|
117 | + public static function render($view, array $context = [], $type = null) |
|
118 | + { |
|
119 | + $viewBuilder = static::getViewBuilder(); |
|
120 | + $viewObject = $viewBuilder->create($view, $type); |
|
121 | 121 | |
122 | - return $viewObject->render($context); |
|
123 | - } |
|
122 | + return $viewObject->render($context); |
|
123 | + } |
|
124 | 124 | } |
@@ -25,19 +25,19 @@ |
||
25 | 25 | class URIs extends ArrayCollection |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Create a new URIs from a Symfony Finder instance. |
|
30 | - * |
|
31 | - * @since 0.1.3 |
|
32 | - * |
|
33 | - * @param Finder $finder The Finder instance to create the URI collection from. |
|
34 | - * |
|
35 | - * @return URIs New URIs instance. |
|
36 | - */ |
|
37 | - public static function fromFinder(Finder $finder): URIs |
|
38 | - { |
|
39 | - $elements = array_keys(iterator_to_array($finder)); |
|
28 | + /** |
|
29 | + * Create a new URIs from a Symfony Finder instance. |
|
30 | + * |
|
31 | + * @since 0.1.3 |
|
32 | + * |
|
33 | + * @param Finder $finder The Finder instance to create the URI collection from. |
|
34 | + * |
|
35 | + * @return URIs New URIs instance. |
|
36 | + */ |
|
37 | + public static function fromFinder(Finder $finder): URIs |
|
38 | + { |
|
39 | + $elements = array_keys(iterator_to_array($finder)); |
|
40 | 40 | |
41 | - return new static($elements); |
|
42 | - } |
|
41 | + return new static($elements); |
|
42 | + } |
|
43 | 43 | } |
@@ -22,25 +22,25 @@ |
||
22 | 22 | interface Location |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Get the first URI that matches the given criteria. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @param array $criteria Criteria to match. |
|
31 | - * |
|
32 | - * @return string|false URI that matches the criteria or false if none found. |
|
33 | - */ |
|
34 | - public function getURI(array $criteria); |
|
25 | + /** |
|
26 | + * Get the first URI that matches the given criteria. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @param array $criteria Criteria to match. |
|
31 | + * |
|
32 | + * @return string|false URI that matches the criteria or false if none found. |
|
33 | + */ |
|
34 | + public function getURI(array $criteria); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get all URIs that match the given criteria. |
|
38 | - * |
|
39 | - * @since 0.1.1 |
|
40 | - * |
|
41 | - * @param array $criteria Criteria to match. |
|
42 | - * |
|
43 | - * @return URIs Collection of URIs that matches the criteria or an empty collection if none found. |
|
44 | - */ |
|
45 | - public function getURIs(array $criteria): URIs; |
|
36 | + /** |
|
37 | + * Get all URIs that match the given criteria. |
|
38 | + * |
|
39 | + * @since 0.1.1 |
|
40 | + * |
|
41 | + * @param array $criteria Criteria to match. |
|
42 | + * |
|
43 | + * @return URIs Collection of URIs that matches the criteria or an empty collection if none found. |
|
44 | + */ |
|
45 | + public function getURIs(array $criteria): URIs; |
|
46 | 46 | } |
@@ -24,37 +24,37 @@ |
||
24 | 24 | class Locations extends ArrayCollection |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Adds a location at the end of the collection if it does not already exist. |
|
29 | - * |
|
30 | - * @param mixed $location The location to add. |
|
31 | - * |
|
32 | - * @return bool Whether the location was added or not. |
|
33 | - */ |
|
34 | - public function add($location): bool |
|
35 | - { |
|
36 | - if ($this->hasLocation($location)) { |
|
37 | - return false; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Adds a location at the end of the collection if it does not already exist. |
|
29 | + * |
|
30 | + * @param mixed $location The location to add. |
|
31 | + * |
|
32 | + * @return bool Whether the location was added or not. |
|
33 | + */ |
|
34 | + public function add($location): bool |
|
35 | + { |
|
36 | + if ($this->hasLocation($location)) { |
|
37 | + return false; |
|
38 | + } |
|
39 | 39 | |
40 | - return parent::add($location); |
|
41 | - } |
|
40 | + return parent::add($location); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Check whether a given location is already registered. |
|
45 | - * |
|
46 | - * For two locations to be equal, both their path and their extensions must be the same. |
|
47 | - * |
|
48 | - * @since 0.1.1 |
|
49 | - * |
|
50 | - * @param Location $location Location to check the existence of. |
|
51 | - * |
|
52 | - * @return bool Whether the location is already registered or not. |
|
53 | - */ |
|
54 | - public function hasLocation(Location $location): bool |
|
55 | - { |
|
56 | - return $this->exists(function ($key, $element) use ($location) { |
|
57 | - return $location == $element; |
|
58 | - }); |
|
59 | - } |
|
43 | + /** |
|
44 | + * Check whether a given location is already registered. |
|
45 | + * |
|
46 | + * For two locations to be equal, both their path and their extensions must be the same. |
|
47 | + * |
|
48 | + * @since 0.1.1 |
|
49 | + * |
|
50 | + * @param Location $location Location to check the existence of. |
|
51 | + * |
|
52 | + * @return bool Whether the location is already registered or not. |
|
53 | + */ |
|
54 | + public function hasLocation(Location $location): bool |
|
55 | + { |
|
56 | + return $this->exists(function ($key, $element) use ($location) { |
|
57 | + return $location == $element; |
|
58 | + }); |
|
59 | + } |
|
60 | 60 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | */ |
54 | 54 | public function hasLocation(Location $location): bool |
55 | 55 | { |
56 | - return $this->exists(function ($key, $element) use ($location) { |
|
56 | + return $this->exists(function($key, $element) use ($location) { |
|
57 | 57 | return $location == $element; |
58 | 58 | }); |
59 | 59 | } |
@@ -22,14 +22,14 @@ |
||
22 | 22 | interface Findable |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Check whether the Findable can handle an individual criterion. |
|
27 | - * |
|
28 | - * @since 0.1.0 |
|
29 | - * |
|
30 | - * @param mixed $criterion Criterion to check. |
|
31 | - * |
|
32 | - * @return bool Whether the Findable can handle the criterion. |
|
33 | - */ |
|
34 | - public function canHandle($criterion): bool; |
|
25 | + /** |
|
26 | + * Check whether the Findable can handle an individual criterion. |
|
27 | + * |
|
28 | + * @since 0.1.0 |
|
29 | + * |
|
30 | + * @param mixed $criterion Criterion to check. |
|
31 | + * |
|
32 | + * @return bool Whether the Findable can handle the criterion. |
|
33 | + */ |
|
34 | + public function canHandle($criterion): bool; |
|
35 | 35 | } |
@@ -24,24 +24,24 @@ |
||
24 | 24 | class Extensions extends ArrayCollection |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Check whether a given URI has a specific extension. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param string $uri URI to check the extension of. |
|
33 | - * @param string $extension Extension to check for. |
|
34 | - * |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public static function hasExtension(string $uri, string $extension): bool |
|
38 | - { |
|
39 | - $uriLength = mb_strlen($uri); |
|
40 | - $extensionLength = mb_strlen($extension); |
|
41 | - if ($extensionLength > $uriLength) { |
|
42 | - return false; |
|
43 | - } |
|
27 | + /** |
|
28 | + * Check whether a given URI has a specific extension. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param string $uri URI to check the extension of. |
|
33 | + * @param string $extension Extension to check for. |
|
34 | + * |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public static function hasExtension(string $uri, string $extension): bool |
|
38 | + { |
|
39 | + $uriLength = mb_strlen($uri); |
|
40 | + $extensionLength = mb_strlen($extension); |
|
41 | + if ($extensionLength > $uriLength) { |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | |
45 | - return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
46 | - } |
|
45 | + return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
46 | + } |
|
47 | 47 | } |
@@ -24,58 +24,58 @@ |
||
24 | 24 | interface View extends Findable |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Check whether the Findable can handle an individual criterion. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param mixed $criterion Criterion to check. |
|
33 | - * |
|
34 | - * @return bool Whether the Findable can handle the criterion. |
|
35 | - */ |
|
36 | - public function canHandle($criterion): bool; |
|
27 | + /** |
|
28 | + * Check whether the Findable can handle an individual criterion. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param mixed $criterion Criterion to check. |
|
33 | + * |
|
34 | + * @return bool Whether the Findable can handle the criterion. |
|
35 | + */ |
|
36 | + public function canHandle($criterion): bool; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Render the view. |
|
40 | - * |
|
41 | - * @since 0.1.0 |
|
42 | - * |
|
43 | - * @param array $context Optional. The context in which to render the view. |
|
44 | - * |
|
45 | - * @return string Rendered HTML. |
|
46 | - */ |
|
47 | - public function render(array $context = []): string; |
|
38 | + /** |
|
39 | + * Render the view. |
|
40 | + * |
|
41 | + * @since 0.1.0 |
|
42 | + * |
|
43 | + * @param array $context Optional. The context in which to render the view. |
|
44 | + * |
|
45 | + * @return string Rendered HTML. |
|
46 | + */ |
|
47 | + public function render(array $context = []): string; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Render a partial view (or section) for a given URI. |
|
51 | - * |
|
52 | - * @since 0.2.0 |
|
53 | - * |
|
54 | - * @param string $view View identifier to create a view for. |
|
55 | - * @param array $context Optional. The context in which to render the view. |
|
56 | - * @param string|null $type Type of view to create. |
|
57 | - * |
|
58 | - * @return string Rendered HTML content. |
|
59 | - */ |
|
60 | - public function section(string $view, array $context = [], $type = null): string; |
|
49 | + /** |
|
50 | + * Render a partial view (or section) for a given URI. |
|
51 | + * |
|
52 | + * @since 0.2.0 |
|
53 | + * |
|
54 | + * @param string $view View identifier to create a view for. |
|
55 | + * @param array $context Optional. The context in which to render the view. |
|
56 | + * @param string|null $type Type of view to create. |
|
57 | + * |
|
58 | + * @return string Rendered HTML content. |
|
59 | + */ |
|
60 | + public function section(string $view, array $context = [], $type = null): string; |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get the entire array of contextual data. |
|
64 | - * |
|
65 | - * @since 0.4.0 |
|
66 | - * |
|
67 | - * @return array Array of contextual data. |
|
68 | - */ |
|
69 | - public function getContext(): array; |
|
62 | + /** |
|
63 | + * Get the entire array of contextual data. |
|
64 | + * |
|
65 | + * @since 0.4.0 |
|
66 | + * |
|
67 | + * @return array Array of contextual data. |
|
68 | + */ |
|
69 | + public function getContext(): array; |
|
70 | 70 | |
71 | - /** |
|
72 | - * Associate a view builder with this view. |
|
73 | - * |
|
74 | - * @since 0.2.0 |
|
75 | - * |
|
76 | - * @param ViewBuilder $builder |
|
77 | - * |
|
78 | - * @return View |
|
79 | - */ |
|
80 | - public function setBuilder(ViewBuilder $builder): View; |
|
71 | + /** |
|
72 | + * Associate a view builder with this view. |
|
73 | + * |
|
74 | + * @since 0.2.0 |
|
75 | + * |
|
76 | + * @param ViewBuilder $builder |
|
77 | + * |
|
78 | + * @return View |
|
79 | + */ |
|
80 | + public function setBuilder(ViewBuilder $builder): View; |
|
81 | 81 | } |