| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | * @param string $uri URI to render. | 
| 47 | 47 | * @param array $context Context in which to render. | 
| 48 | 48 | * | 
| 49 | - * @return callable Rendering callback. | |
| 49 | + * @return string Rendering callback. | |
| 50 | 50 | */ | 
| 51 | 51 | public function getRenderCallback(string $uri, array $context = []): callable | 
| 52 | 52 |      { | 
| @@ -24,32 +24,32 @@ | ||
| 24 | 24 | class NullEngine implements Engine, NullFindable | 
| 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 | |
| 37 | -    { | |
| 38 | - return true; | |
| 39 | - } | |
| 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 | +	{ | |
| 38 | + return true; | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * Get the rendering callback for a given URI. | |
| 43 | - * | |
| 44 | - * @since 0.1.0 | |
| 45 | - * | |
| 46 | - * @param string $uri URI to render. | |
| 47 | - * @param array $context Context in which to render. | |
| 48 | - * | |
| 49 | - * @return callable Rendering callback. | |
| 50 | - */ | |
| 51 | - public function getRenderCallback(string $uri, array $context = []): callable | |
| 52 | -    { | |
| 53 | - return ''; | |
| 54 | - } | |
| 41 | + /** | |
| 42 | + * Get the rendering callback for a given URI. | |
| 43 | + * | |
| 44 | + * @since 0.1.0 | |
| 45 | + * | |
| 46 | + * @param string $uri URI to render. | |
| 47 | + * @param array $context Context in which to render. | |
| 48 | + * | |
| 49 | + * @return callable Rendering callback. | |
| 50 | + */ | |
| 51 | + public function getRenderCallback(string $uri, array $context = []): callable | |
| 52 | +	{ | |
| 53 | + return ''; | |
| 54 | + } | |
| 55 | 55 | } | 
| @@ -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 | */ | 
| @@ -34,264 +34,264 @@ | ||
| 34 | 34 | class ViewBuilder | 
| 35 | 35 |  { | 
| 36 | 36 | |
| 37 | - use ConfigTrait; | |
| 37 | + use ConfigTrait; | |
| 38 | 38 | |
| 39 | - const ENGINE_FINDER_KEY = 'EngineFinder'; | |
| 40 | - const VIEW_FINDER_KEY = 'ViewFinder'; | |
| 39 | + const ENGINE_FINDER_KEY = 'EngineFinder'; | |
| 40 | + const VIEW_FINDER_KEY = 'ViewFinder'; | |
| 41 | 41 | |
| 42 | - /** | |
| 43 | - * BaseViewFinder instance. | |
| 44 | - * | |
| 45 | - * @since 0.1.0 | |
| 46 | - * | |
| 47 | - * @var ViewFinder | |
| 48 | - */ | |
| 49 | - protected $viewFinder; | |
| 42 | + /** | |
| 43 | + * BaseViewFinder instance. | |
| 44 | + * | |
| 45 | + * @since 0.1.0 | |
| 46 | + * | |
| 47 | + * @var ViewFinder | |
| 48 | + */ | |
| 49 | + protected $viewFinder; | |
| 50 | 50 | |
| 51 | - /** | |
| 52 | - * BaseEngineFinder instance. | |
| 53 | - * | |
| 54 | - * @since 0.1.0 | |
| 55 | - * | |
| 56 | - * @var BaseEngineFinder | |
| 57 | - */ | |
| 58 | - protected $engineFinder; | |
| 51 | + /** | |
| 52 | + * BaseEngineFinder instance. | |
| 53 | + * | |
| 54 | + * @since 0.1.0 | |
| 55 | + * | |
| 56 | + * @var BaseEngineFinder | |
| 57 | + */ | |
| 58 | + protected $engineFinder; | |
| 59 | 59 | |
| 60 | - /** | |
| 61 | - * Locations to scan for views. | |
| 62 | - * | |
| 63 | - * @since 0.1.0 | |
| 64 | - * | |
| 65 | - * @var Locations | |
| 66 | - */ | |
| 67 | - protected $locations; | |
| 60 | + /** | |
| 61 | + * Locations to scan for views. | |
| 62 | + * | |
| 63 | + * @since 0.1.0 | |
| 64 | + * | |
| 65 | + * @var Locations | |
| 66 | + */ | |
| 67 | + protected $locations; | |
| 68 | 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 | - public function __construct( | |
| 81 | - ConfigInterface $config = null, | |
| 82 | - ViewFinder $viewFinder = null, | |
| 83 | - BaseEngineFinder $engineFinder = null | |
| 84 | -    ) { | |
| 85 | - $this->processConfig($this->getConfig($config)); | |
| 86 | - $this->viewFinder = $viewFinder; | |
| 87 | - $this->engineFinder = $engineFinder; | |
| 88 | - $this->locations = new Locations(); | |
| 89 | - } | |
| 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 | + public function __construct( | |
| 81 | + ConfigInterface $config = null, | |
| 82 | + ViewFinder $viewFinder = null, | |
| 83 | + BaseEngineFinder $engineFinder = null | |
| 84 | +	) { | |
| 85 | + $this->processConfig($this->getConfig($config)); | |
| 86 | + $this->viewFinder = $viewFinder; | |
| 87 | + $this->engineFinder = $engineFinder; | |
| 88 | + $this->locations = new Locations(); | |
| 89 | + } | |
| 90 | 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 | - * @throws FailedToInstantiateView If the view could not be instantiated. | |
| 101 | - */ | |
| 102 | - public function create(string $view, $type = null): View | |
| 103 | -    { | |
| 104 | - $uri = $this->scanLocations([$view]); | |
| 105 | - $engine = $uri | |
| 106 | - ? $this->getEngine($uri) | |
| 107 | - : false; | |
| 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 | + * @throws FailedToInstantiateView If the view could not be instantiated. | |
| 101 | + */ | |
| 102 | + public function create(string $view, $type = null): View | |
| 103 | +	{ | |
| 104 | + $uri = $this->scanLocations([$view]); | |
| 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 | - $view = (null === $type) | |
| 143 | - ? $this->getViewFinder()->find([$uri], $engine) | |
| 144 | - : $this->resolveType($type, $uri, $engine); | |
| 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 | + $view = (null === $type) | |
| 143 | + ? $this->getViewFinder()->find([$uri], $engine) | |
| 144 | + : $this->resolveType($type, $uri, $engine); | |
| 145 | 145 | |
| 146 | - return $view->setBuilder($this); | |
| 147 | - } | |
| 146 | + return $view->setBuilder($this); | |
| 147 | + } | |
| 148 | 148 | |
| 149 | - /** | |
| 150 | - * Get the ViewFinder instance. | |
| 151 | - * | |
| 152 | - * @since 0.1.0 | |
| 153 | - * | |
| 154 | - * @return ViewFinder Instance of a BaseViewFinder. | |
| 155 | - */ | |
| 156 | - public function getViewFinder(): ViewFinder | |
| 157 | -    { | |
| 158 | - return $this->getFinder($viewFinder, static::VIEW_FINDER_KEY); | |
| 159 | - } | |
| 149 | + /** | |
| 150 | + * Get the ViewFinder instance. | |
| 151 | + * | |
| 152 | + * @since 0.1.0 | |
| 153 | + * | |
| 154 | + * @return ViewFinder Instance of a BaseViewFinder. | |
| 155 | + */ | |
| 156 | + public function getViewFinder(): ViewFinder | |
| 157 | +	{ | |
| 158 | + return $this->getFinder($viewFinder, static::VIEW_FINDER_KEY); | |
| 159 | + } | |
| 160 | 160 | |
| 161 | - /** | |
| 162 | - * Get the EngineFinder instance. | |
| 163 | - * | |
| 164 | - * @since 0.1.0 | |
| 165 | - * | |
| 166 | - * @return EngineFinder Instance of a BaseEngineFinder. | |
| 167 | - */ | |
| 168 | - public function getEngineFinder(): EngineFinder | |
| 169 | -    { | |
| 170 | - return $this->getFinder($this->engineFinder, static::ENGINE_FINDER_KEY); | |
| 171 | - } | |
| 161 | + /** | |
| 162 | + * Get the EngineFinder instance. | |
| 163 | + * | |
| 164 | + * @since 0.1.0 | |
| 165 | + * | |
| 166 | + * @return EngineFinder Instance of a BaseEngineFinder. | |
| 167 | + */ | |
| 168 | + public function getEngineFinder(): EngineFinder | |
| 169 | +	{ | |
| 170 | + return $this->getFinder($this->engineFinder, static::ENGINE_FINDER_KEY); | |
| 171 | + } | |
| 172 | 172 | |
| 173 | - /** | |
| 174 | - * Add a location to scan with the BaseViewFinder. | |
| 175 | - * | |
| 176 | - * @since 0.1.0 | |
| 177 | - * | |
| 178 | - * @param Location $location Location to scan with the BaseViewFinder. | |
| 179 | - */ | |
| 180 | - public function addLocation(Location $location) | |
| 181 | -    { | |
| 182 | - $this->locations->add($location); | |
| 183 | - } | |
| 173 | + /** | |
| 174 | + * Add a location to scan with the BaseViewFinder. | |
| 175 | + * | |
| 176 | + * @since 0.1.0 | |
| 177 | + * | |
| 178 | + * @param Location $location Location to scan with the BaseViewFinder. | |
| 179 | + */ | |
| 180 | + public function addLocation(Location $location) | |
| 181 | +	{ | |
| 182 | + $this->locations->add($location); | |
| 183 | + } | |
| 184 | 184 | |
| 185 | - /** | |
| 186 | - * Get the collection of locations registered with this ViewBuilder. | |
| 187 | - * | |
| 188 | - * @since 0.1.3 | |
| 189 | - * | |
| 190 | - * @return Locations Collection of locations. | |
| 191 | - */ | |
| 192 | - public function getLocations() | |
| 193 | -    { | |
| 194 | - return $this->locations; | |
| 195 | - } | |
| 185 | + /** | |
| 186 | + * Get the collection of locations registered with this ViewBuilder. | |
| 187 | + * | |
| 188 | + * @since 0.1.3 | |
| 189 | + * | |
| 190 | + * @return Locations Collection of locations. | |
| 191 | + */ | |
| 192 | + public function getLocations() | |
| 193 | +	{ | |
| 194 | + return $this->locations; | |
| 195 | + } | |
| 196 | 196 | |
| 197 | - /** | |
| 198 | - * Scan Locations for an URI that matches the specified criteria. | |
| 199 | - * | |
| 200 | - * @since 0.1.0 | |
| 201 | - * | |
| 202 | - * @param array $criteria Criteria to match. | |
| 203 | - * | |
| 204 | - * @return string|false URI of the requested view, or false if not found. | |
| 205 | - */ | |
| 206 | - public function scanLocations(array $criteria) | |
| 207 | -    { | |
| 208 | -        $uris = $this->locations->map(function ($location) use ($criteria) { | |
| 209 | - /** @var Location $location */ | |
| 210 | - return $location->getURI($criteria); | |
| 211 | -        })->filter(function ($uri) { | |
| 212 | - return false !== $uri; | |
| 213 | - }); | |
| 197 | + /** | |
| 198 | + * Scan Locations for an URI that matches the specified criteria. | |
| 199 | + * | |
| 200 | + * @since 0.1.0 | |
| 201 | + * | |
| 202 | + * @param array $criteria Criteria to match. | |
| 203 | + * | |
| 204 | + * @return string|false URI of the requested view, or false if not found. | |
| 205 | + */ | |
| 206 | + public function scanLocations(array $criteria) | |
| 207 | +	{ | |
| 208 | +		$uris = $this->locations->map(function ($location) use ($criteria) { | |
| 209 | + /** @var Location $location */ | |
| 210 | + return $location->getURI($criteria); | |
| 211 | +		})->filter(function ($uri) { | |
| 212 | + return false !== $uri; | |
| 213 | + }); | |
| 214 | 214 | |
| 215 | - return $uris->count() > 0 ? $uris->first() : false; | |
| 216 | - } | |
| 215 | + return $uris->count() > 0 ? $uris->first() : false; | |
| 216 | + } | |
| 217 | 217 | |
| 218 | - /** | |
| 219 | - * Get a finder instance. | |
| 220 | - * | |
| 221 | - * @since 0.1.1 | |
| 222 | - * | |
| 223 | - * @param mixed $property Property to use. | |
| 224 | - * @param string $key Configuration key to use. | |
| 225 | - * | |
| 226 | - * @return ViewFinder|EngineFinder The requested finder instance. | |
| 227 | - */ | |
| 228 | - protected function getFinder(&$property, $key) | |
| 229 | -    { | |
| 230 | -        if (null === $property) { | |
| 231 | - $finderClass = $this->config->getKey($key, 'ClassName'); | |
| 232 | - $property = new $finderClass($this->config->getSubConfig($key)); | |
| 233 | - } | |
| 218 | + /** | |
| 219 | + * Get a finder instance. | |
| 220 | + * | |
| 221 | + * @since 0.1.1 | |
| 222 | + * | |
| 223 | + * @param mixed $property Property to use. | |
| 224 | + * @param string $key Configuration key to use. | |
| 225 | + * | |
| 226 | + * @return ViewFinder|EngineFinder The requested finder instance. | |
| 227 | + */ | |
| 228 | + protected function getFinder(&$property, $key) | |
| 229 | +	{ | |
| 230 | +		if (null === $property) { | |
| 231 | + $finderClass = $this->config->getKey($key, 'ClassName'); | |
| 232 | + $property = new $finderClass($this->config->getSubConfig($key)); | |
| 233 | + } | |
| 234 | 234 | |
| 235 | - return $property; | |
| 236 | - } | |
| 235 | + return $property; | |
| 236 | + } | |
| 237 | 237 | |
| 238 | - /** | |
| 239 | - * Resolve the view type. | |
| 240 | - * | |
| 241 | - * @since 0.1.0 | |
| 242 | - * | |
| 243 | - * @param mixed $type Type of view that was requested. | |
| 244 | - * @param string $uri URI to get a view for. | |
| 245 | - * @param Engine|null $engine Engine to use for the view. | |
| 246 | - * | |
| 247 | - * @return View Resolved View object. | |
| 248 | - * @throws FailedToInstantiateView If the view type could not be resolved. | |
| 249 | - */ | |
| 250 | - protected function resolveType($type, string $uri, Engine $engine = null): View | |
| 251 | -    { | |
| 252 | - $configKey = [static::VIEW_FINDER_KEY, 'Views', $type]; | |
| 238 | + /** | |
| 239 | + * Resolve the view type. | |
| 240 | + * | |
| 241 | + * @since 0.1.0 | |
| 242 | + * | |
| 243 | + * @param mixed $type Type of view that was requested. | |
| 244 | + * @param string $uri URI to get a view for. | |
| 245 | + * @param Engine|null $engine Engine to use for the view. | |
| 246 | + * | |
| 247 | + * @return View Resolved View object. | |
| 248 | + * @throws FailedToInstantiateView If the view type could not be resolved. | |
| 249 | + */ | |
| 250 | + protected function resolveType($type, string $uri, Engine $engine = null): View | |
| 251 | +	{ | |
| 252 | + $configKey = [static::VIEW_FINDER_KEY, 'Views', $type]; | |
| 253 | 253 | |
| 254 | -        if (is_string($type) && $this->config->hasKey($configKey)) { | |
| 255 | - $className = $this->config->getKey($configKey); | |
| 256 | - $type = new $className($uri, $engine); | |
| 257 | - } | |
| 254 | +		if (is_string($type) && $this->config->hasKey($configKey)) { | |
| 255 | + $className = $this->config->getKey($configKey); | |
| 256 | + $type = new $className($uri, $engine); | |
| 257 | + } | |
| 258 | 258 | |
| 259 | -        if (is_string($type)) { | |
| 260 | - $type = new $type($uri, $engine); | |
| 261 | - } | |
| 259 | +		if (is_string($type)) { | |
| 260 | + $type = new $type($uri, $engine); | |
| 261 | + } | |
| 262 | 262 | |
| 263 | -        if (is_callable($type)) { | |
| 264 | - $type = $type($uri, $engine); | |
| 265 | - } | |
| 263 | +		if (is_callable($type)) { | |
| 264 | + $type = $type($uri, $engine); | |
| 265 | + } | |
| 266 | 266 | |
| 267 | -        if (! $type instanceof View) { | |
| 268 | - throw new FailedToInstantiateView( | |
| 269 | - sprintf( | |
| 270 | -                    _('Could not instantiate view "%s".'), | |
| 271 | - serialize($type) | |
| 272 | - ) | |
| 273 | - ); | |
| 274 | - } | |
| 267 | +		if (! $type instanceof View) { | |
| 268 | + throw new FailedToInstantiateView( | |
| 269 | + sprintf( | |
| 270 | +					_('Could not instantiate view "%s".'), | |
| 271 | + serialize($type) | |
| 272 | + ) | |
| 273 | + ); | |
| 274 | + } | |
| 275 | 275 | |
| 276 | - return $type; | |
| 277 | - } | |
| 276 | + return $type; | |
| 277 | + } | |
| 278 | 278 | |
| 279 | - /** | |
| 280 | - * Get the configuration to use in the ViewBuilder. | |
| 281 | - * | |
| 282 | - * @since 0.2.0 | |
| 283 | - * | |
| 284 | - * @param ConfigInterface|array $config Config to merge with defaults. | |
| 285 | - * | |
| 286 | - * @return ConfigInterface Configuration passed in through the constructor. | |
| 287 | - */ | |
| 288 | - protected function getConfig($config = []): ConfigInterface | |
| 289 | -    { | |
| 290 | - $defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config); | |
| 291 | - $config = $config | |
| 292 | - ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) | |
| 293 | - : $defaults; | |
| 279 | + /** | |
| 280 | + * Get the configuration to use in the ViewBuilder. | |
| 281 | + * | |
| 282 | + * @since 0.2.0 | |
| 283 | + * | |
| 284 | + * @param ConfigInterface|array $config Config to merge with defaults. | |
| 285 | + * | |
| 286 | + * @return ConfigInterface Configuration passed in through the constructor. | |
| 287 | + */ | |
| 288 | + protected function getConfig($config = []): ConfigInterface | |
| 289 | +	{ | |
| 290 | + $defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config); | |
| 291 | + $config = $config | |
| 292 | + ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) | |
| 293 | + : $defaults; | |
| 294 | 294 | |
| 295 | -        return $config->getSubConfig('BrightNucleus\View'); | |
| 296 | - } | |
| 295 | +		return $config->getSubConfig('BrightNucleus\View'); | |
| 296 | + } | |
| 297 | 297 | } | 
| @@ -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 | } | 
| @@ -28,162 +28,162 @@ | ||
| 28 | 28 | class FilesystemLocation implements Location | 
| 29 | 29 |  { | 
| 30 | 30 | |
| 31 | - /** | |
| 32 | - * Path that this location points to. | |
| 33 | - * | |
| 34 | - * @since 0.1.0 | |
| 35 | - * | |
| 36 | - * @var string | |
| 37 | - */ | |
| 38 | - protected $path; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Extensions that this location can accept. | |
| 42 | - * | |
| 43 | - * @since 0.1.0 | |
| 44 | - * | |
| 45 | - * @var Extensions | |
| 46 | - */ | |
| 47 | - protected $extensions; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Instantiate a FilesystemLocation object. | |
| 51 | - * | |
| 52 | - * @since 0.1.0 | |
| 53 | - * | |
| 54 | - * @param string $path Path that this location points to. | |
| 55 | - * @param Extensions|array|string|null $extensions Optional. Extensions that this location can accept. | |
| 56 | - */ | |
| 57 | - public function __construct(string $path, $extensions = null) | |
| 58 | -    { | |
| 59 | - $this->path = $path; | |
| 60 | - $this->extensions = $this->validateExtensions($extensions); | |
| 61 | - } | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Get the first URI that matches the given criteria. | |
| 65 | - * | |
| 66 | - * @since 0.1.0 | |
| 67 | - * | |
| 68 | - * @param array $criteria Criteria to match. | |
| 69 | - * | |
| 70 | - * @return string|false URI that matches the criteria or false if none found. | |
| 71 | - */ | |
| 72 | - public function getURI(array $criteria) | |
| 73 | -    { | |
| 74 | - $uris = $this->getURIs($criteria); | |
| 75 | - | |
| 76 | - return $uris->count() > 0 | |
| 77 | - ? $this->getURIs($criteria)->first() | |
| 78 | - : false; | |
| 79 | - } | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * Get all URIs that match the given criteria. | |
| 83 | - * | |
| 84 | - * @since 0.1.1 | |
| 85 | - * | |
| 86 | - * @param array $criteria Criteria to match. | |
| 87 | - * | |
| 88 | - * @return URIs URIs that match the criteria or an empty collection if none found. | |
| 89 | - */ | |
| 90 | - public function getURIs(array $criteria): URIs | |
| 91 | -    { | |
| 92 | - $uris = new URIs(); | |
| 93 | - | |
| 94 | -        foreach ($this->extensions as $extension) { | |
| 95 | - $finder = new Finder(); | |
| 96 | - | |
| 97 | -            try { | |
| 98 | - $finder->files() | |
| 99 | - ->name($this->getNamePattern($criteria, $extension)) | |
| 100 | - ->in($this->getPathPattern()); | |
| 101 | -                foreach ($finder as $file) { | |
| 102 | - /** @var SplFileInfo $file */ | |
| 103 | - $uris->add($file->getPathname()); | |
| 104 | - } | |
| 105 | -            } catch (Exception $exception) { | |
| 106 | - // Fail silently; | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - return $uris; | |
| 111 | - } | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * Get the name pattern to pass to the file finder. | |
| 115 | - * | |
| 116 | - * @since 0.1.3 | |
| 117 | - * | |
| 118 | - * @param array $criteria Criteria to match. | |
| 119 | - * @param string $extension Extension to match. | |
| 120 | - * | |
| 121 | - * @return string Name pattern to pass to the file finder. | |
| 122 | - */ | |
| 123 | - protected function getNamePattern(array $criteria, string $extension): string | |
| 124 | -    { | |
| 125 | - $names = []; | |
| 126 | - | |
| 127 | -        $names[] = array_map(function ($criterion) use ($extension) { | |
| 128 | - $criterion = URIHelper::getFilename($criterion); | |
| 129 | - | |
| 130 | - return empty($extension) || URIHelper::hasExtension($criterion, $extension) | |
| 131 | - ? $criterion | |
| 132 | - : $criterion . $extension; | |
| 133 | - }, $criteria)[0]; | |
| 134 | - | |
| 135 | - return $this->arrayToRegexPattern(array_unique($names)); | |
| 136 | - } | |
| 137 | - | |
| 138 | - /** | |
| 139 | - * Get the path pattern to pass to the file finder. | |
| 140 | - * | |
| 141 | - * @since 0.1.3 | |
| 142 | - * | |
| 143 | - * @return string Path pattern to pass to the file finder. | |
| 144 | - */ | |
| 145 | - protected function getPathPattern(): string | |
| 146 | -    { | |
| 147 | - return $this->path; | |
| 148 | - } | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * Get an array as a regular expression pattern string. | |
| 152 | - * | |
| 153 | - * @since 0.1.3 | |
| 154 | - * | |
| 155 | - * @param array $array Array to generate the pattern for. | |
| 156 | - * | |
| 157 | - * @return string Generated regular expression pattern. | |
| 158 | - */ | |
| 159 | - protected function arrayToRegexPattern(array $array): string | |
| 160 | -    { | |
| 161 | -        $array = array_map(function ($entry) { | |
| 162 | - return preg_quote($entry); | |
| 163 | - }, $array); | |
| 164 | - | |
| 165 | -        return '/' . implode('|', $array) . '/'; | |
| 166 | - } | |
| 167 | - | |
| 168 | - /** | |
| 169 | - * Validate the extensions and return a collection. | |
| 170 | - * | |
| 171 | - * @since 0.1.1 | |
| 172 | - * | |
| 173 | - * @param Extensions|array|string|null $extensions Extensions to validate. | |
| 174 | - * | |
| 175 | - * @return Extensions Validated extensions collection. | |
| 176 | - */ | |
| 177 | - protected function validateExtensions($extensions): Extensions | |
| 178 | -    { | |
| 179 | -        if (empty($extensions)) { | |
| 180 | - $extensions = new Extensions(['']); | |
| 181 | - } | |
| 182 | - | |
| 183 | -        if (! $extensions instanceof Extensions) { | |
| 184 | - $extensions = new Extensions((array)$extensions); | |
| 185 | - } | |
| 186 | - | |
| 187 | - return $extensions; | |
| 188 | - } | |
| 31 | + /** | |
| 32 | + * Path that this location points to. | |
| 33 | + * | |
| 34 | + * @since 0.1.0 | |
| 35 | + * | |
| 36 | + * @var string | |
| 37 | + */ | |
| 38 | + protected $path; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Extensions that this location can accept. | |
| 42 | + * | |
| 43 | + * @since 0.1.0 | |
| 44 | + * | |
| 45 | + * @var Extensions | |
| 46 | + */ | |
| 47 | + protected $extensions; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * Instantiate a FilesystemLocation object. | |
| 51 | + * | |
| 52 | + * @since 0.1.0 | |
| 53 | + * | |
| 54 | + * @param string $path Path that this location points to. | |
| 55 | + * @param Extensions|array|string|null $extensions Optional. Extensions that this location can accept. | |
| 56 | + */ | |
| 57 | + public function __construct(string $path, $extensions = null) | |
| 58 | +	{ | |
| 59 | + $this->path = $path; | |
| 60 | + $this->extensions = $this->validateExtensions($extensions); | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Get the first URI that matches the given criteria. | |
| 65 | + * | |
| 66 | + * @since 0.1.0 | |
| 67 | + * | |
| 68 | + * @param array $criteria Criteria to match. | |
| 69 | + * | |
| 70 | + * @return string|false URI that matches the criteria or false if none found. | |
| 71 | + */ | |
| 72 | + public function getURI(array $criteria) | |
| 73 | +	{ | |
| 74 | + $uris = $this->getURIs($criteria); | |
| 75 | + | |
| 76 | + return $uris->count() > 0 | |
| 77 | + ? $this->getURIs($criteria)->first() | |
| 78 | + : false; | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Get all URIs that match the given criteria. | |
| 83 | + * | |
| 84 | + * @since 0.1.1 | |
| 85 | + * | |
| 86 | + * @param array $criteria Criteria to match. | |
| 87 | + * | |
| 88 | + * @return URIs URIs that match the criteria or an empty collection if none found. | |
| 89 | + */ | |
| 90 | + public function getURIs(array $criteria): URIs | |
| 91 | +	{ | |
| 92 | + $uris = new URIs(); | |
| 93 | + | |
| 94 | +		foreach ($this->extensions as $extension) { | |
| 95 | + $finder = new Finder(); | |
| 96 | + | |
| 97 | +			try { | |
| 98 | + $finder->files() | |
| 99 | + ->name($this->getNamePattern($criteria, $extension)) | |
| 100 | + ->in($this->getPathPattern()); | |
| 101 | +				foreach ($finder as $file) { | |
| 102 | + /** @var SplFileInfo $file */ | |
| 103 | + $uris->add($file->getPathname()); | |
| 104 | + } | |
| 105 | +			} catch (Exception $exception) { | |
| 106 | + // Fail silently; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + return $uris; | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Get the name pattern to pass to the file finder. | |
| 115 | + * | |
| 116 | + * @since 0.1.3 | |
| 117 | + * | |
| 118 | + * @param array $criteria Criteria to match. | |
| 119 | + * @param string $extension Extension to match. | |
| 120 | + * | |
| 121 | + * @return string Name pattern to pass to the file finder. | |
| 122 | + */ | |
| 123 | + protected function getNamePattern(array $criteria, string $extension): string | |
| 124 | +	{ | |
| 125 | + $names = []; | |
| 126 | + | |
| 127 | +		$names[] = array_map(function ($criterion) use ($extension) { | |
| 128 | + $criterion = URIHelper::getFilename($criterion); | |
| 129 | + | |
| 130 | + return empty($extension) || URIHelper::hasExtension($criterion, $extension) | |
| 131 | + ? $criterion | |
| 132 | + : $criterion . $extension; | |
| 133 | + }, $criteria)[0]; | |
| 134 | + | |
| 135 | + return $this->arrayToRegexPattern(array_unique($names)); | |
| 136 | + } | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * Get the path pattern to pass to the file finder. | |
| 140 | + * | |
| 141 | + * @since 0.1.3 | |
| 142 | + * | |
| 143 | + * @return string Path pattern to pass to the file finder. | |
| 144 | + */ | |
| 145 | + protected function getPathPattern(): string | |
| 146 | +	{ | |
| 147 | + return $this->path; | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Get an array as a regular expression pattern string. | |
| 152 | + * | |
| 153 | + * @since 0.1.3 | |
| 154 | + * | |
| 155 | + * @param array $array Array to generate the pattern for. | |
| 156 | + * | |
| 157 | + * @return string Generated regular expression pattern. | |
| 158 | + */ | |
| 159 | + protected function arrayToRegexPattern(array $array): string | |
| 160 | +	{ | |
| 161 | +		$array = array_map(function ($entry) { | |
| 162 | + return preg_quote($entry); | |
| 163 | + }, $array); | |
| 164 | + | |
| 165 | +		return '/' . implode('|', $array) . '/'; | |
| 166 | + } | |
| 167 | + | |
| 168 | + /** | |
| 169 | + * Validate the extensions and return a collection. | |
| 170 | + * | |
| 171 | + * @since 0.1.1 | |
| 172 | + * | |
| 173 | + * @param Extensions|array|string|null $extensions Extensions to validate. | |
| 174 | + * | |
| 175 | + * @return Extensions Validated extensions collection. | |
| 176 | + */ | |
| 177 | + protected function validateExtensions($extensions): Extensions | |
| 178 | +	{ | |
| 179 | +		if (empty($extensions)) { | |
| 180 | + $extensions = new Extensions(['']); | |
| 181 | + } | |
| 182 | + | |
| 183 | +		if (! $extensions instanceof Extensions) { | |
| 184 | + $extensions = new Extensions((array)$extensions); | |
| 185 | + } | |
| 186 | + | |
| 187 | + return $extensions; | |
| 188 | + } | |
| 189 | 189 | } | 
| @@ -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 | } | 
| @@ -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 | } | 
| @@ -22,23 +22,23 @@ | ||
| 22 | 22 | interface Finder | 
| 23 | 23 |  { | 
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * Find a result based on a specific criteria. | |
| 27 | - * | |
| 28 | - * @since 0.1.0 | |
| 29 | - * | |
| 30 | - * @param array $criteria Criteria to search for. | |
| 31 | - * | |
| 32 | - * @return mixed Result of the search. | |
| 33 | - */ | |
| 34 | - public function find(array $criteria); | |
| 25 | + /** | |
| 26 | + * Find a result based on a specific criteria. | |
| 27 | + * | |
| 28 | + * @since 0.1.0 | |
| 29 | + * | |
| 30 | + * @param array $criteria Criteria to search for. | |
| 31 | + * | |
| 32 | + * @return mixed Result of the search. | |
| 33 | + */ | |
| 34 | + public function find(array $criteria); | |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * Get the NullObject. | |
| 38 | - * | |
| 39 | - * @since 0.1.1 | |
| 40 | - * | |
| 41 | - * @return NullFindable NullObject for the current Finder. | |
| 42 | - */ | |
| 43 | - public function getNullObject(): NullFindable; | |
| 36 | + /** | |
| 37 | + * Get the NullObject. | |
| 38 | + * | |
| 39 | + * @since 0.1.1 | |
| 40 | + * | |
| 41 | + * @return NullFindable NullObject for the current Finder. | |
| 42 | + */ | |
| 43 | + public function getNullObject(): NullFindable; | |
| 44 | 44 | } |