@@ -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 | } |
@@ -22,38 +22,38 @@ |
||
| 22 | 22 | class URIHelper |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Check whether a given URI has a specific extension. |
|
| 27 | - * |
|
| 28 | - * @since 0.1.3 |
|
| 29 | - * |
|
| 30 | - * @param string $uri URI to check the extension of. |
|
| 31 | - * @param string $extension Extension to check for. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public static function hasExtension(string $uri, string $extension): bool |
|
| 36 | - { |
|
| 37 | - $uriLength = mb_strlen($uri); |
|
| 38 | - $extensionLength = mb_strlen($extension); |
|
| 39 | - if ($extensionLength > $uriLength) { |
|
| 40 | - return false; |
|
| 41 | - } |
|
| 25 | + /** |
|
| 26 | + * Check whether a given URI has a specific extension. |
|
| 27 | + * |
|
| 28 | + * @since 0.1.3 |
|
| 29 | + * |
|
| 30 | + * @param string $uri URI to check the extension of. |
|
| 31 | + * @param string $extension Extension to check for. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public static function hasExtension(string $uri, string $extension): bool |
|
| 36 | + { |
|
| 37 | + $uriLength = mb_strlen($uri); |
|
| 38 | + $extensionLength = mb_strlen($extension); |
|
| 39 | + if ($extensionLength > $uriLength) { |
|
| 40 | + return false; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
| 44 | - } |
|
| 43 | + return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the filename for an URI. |
|
| 48 | - * |
|
| 49 | - * @since 0.1.3 |
|
| 50 | - * |
|
| 51 | - * @param string $uri URI to get the filename from. |
|
| 52 | - * |
|
| 53 | - * @return string Filename without path. |
|
| 54 | - */ |
|
| 55 | - public static function getFilename(string $uri): String |
|
| 56 | - { |
|
| 57 | - return basename($uri); |
|
| 58 | - } |
|
| 46 | + /** |
|
| 47 | + * Get the filename for an URI. |
|
| 48 | + * |
|
| 49 | + * @since 0.1.3 |
|
| 50 | + * |
|
| 51 | + * @param string $uri URI to get the filename from. |
|
| 52 | + * |
|
| 53 | + * @return string Filename without path. |
|
| 54 | + */ |
|
| 55 | + public static function getFilename(string $uri): String |
|
| 56 | + { |
|
| 57 | + return basename($uri); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -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 | } |