@@ -22,17 +22,17 @@ |
||
| 22 | 22 | class BaseView extends AbstractView |
| 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) |
|
| 35 | - { |
|
| 36 | - return true; |
|
| 37 | - } |
|
| 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) |
|
| 35 | + { |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -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); |
|
| 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); |
|
| 35 | 35 | } |
@@ -24,32 +24,32 @@ |
||
| 24 | 24 | class NullEngine implements EngineInterface, NullObject |
| 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) |
|
| 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) |
|
| 37 | + { |
|
| 38 | + return true; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Render 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 string Rendered HTML. |
|
| 50 | - */ |
|
| 51 | - public function render($uri, array $context = []) |
|
| 52 | - { |
|
| 53 | - return ''; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Render 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 string Rendered HTML. |
|
| 50 | + */ |
|
| 51 | + public function render($uri, array $context = []) |
|
| 52 | + { |
|
| 53 | + return ''; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -22,23 +22,23 @@ |
||
| 22 | 22 | interface FinderInterface |
| 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 NullObject NullObject for the current Finder. |
|
| 42 | - */ |
|
| 43 | - public function getNullObject(); |
|
| 36 | + /** |
|
| 37 | + * Get the NullObject. |
|
| 38 | + * |
|
| 39 | + * @since 0.1.1 |
|
| 40 | + * |
|
| 41 | + * @return NullObject NullObject for the current Finder. |
|
| 42 | + */ |
|
| 43 | + public function getNullObject(); |
|
| 44 | 44 | } |
@@ -146,7 +146,7 @@ |
||
| 146 | 146 | */ |
| 147 | 147 | protected function initializeNullObject() |
| 148 | 148 | { |
| 149 | - if (! is_object($this->nullObject)) { |
|
| 149 | + if ( ! is_object($this->nullObject)) { |
|
| 150 | 150 | $this->nullObject = new $this->nullObject(); |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -26,128 +26,128 @@ |
||
| 26 | 26 | abstract class AbstractFinder implements FinderInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - use ConfigTrait; |
|
| 29 | + use ConfigTrait; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Array of Findables that the Finder can iterate through to find a match. |
|
| 33 | - * |
|
| 34 | - * @since 0.1.0 |
|
| 35 | - * |
|
| 36 | - * @var Findable[] |
|
| 37 | - */ |
|
| 38 | - protected $findables; |
|
| 31 | + /** |
|
| 32 | + * Array of Findables that the Finder can iterate through to find a match. |
|
| 33 | + * |
|
| 34 | + * @since 0.1.0 |
|
| 35 | + * |
|
| 36 | + * @var Findable[] |
|
| 37 | + */ |
|
| 38 | + protected $findables; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * NullObject that is returned if the Finder could not find a match. |
|
| 42 | - * |
|
| 43 | - * @since 0.1.0 |
|
| 44 | - * |
|
| 45 | - * @var NullObject |
|
| 46 | - */ |
|
| 47 | - protected $nullObject; |
|
| 40 | + /** |
|
| 41 | + * NullObject that is returned if the Finder could not find a match. |
|
| 42 | + * |
|
| 43 | + * @since 0.1.0 |
|
| 44 | + * |
|
| 45 | + * @var NullObject |
|
| 46 | + */ |
|
| 47 | + protected $nullObject; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Instantiate an AbstractFinder object. |
|
| 51 | - * |
|
| 52 | - * @since 0.1.0 |
|
| 53 | - * |
|
| 54 | - * @param ConfigInterface $config Configuration of the EngineFinder. |
|
| 55 | - * |
|
| 56 | - * @throws FailedToProcessConfigException If the config could not be processed. |
|
| 57 | - */ |
|
| 58 | - public function __construct(ConfigInterface $config) |
|
| 59 | - { |
|
| 60 | - $this->processConfig($config); |
|
| 61 | - $this->registerFindables($this->config); |
|
| 62 | - $this->registerNullObject($this->config); |
|
| 63 | - } |
|
| 49 | + /** |
|
| 50 | + * Instantiate an AbstractFinder object. |
|
| 51 | + * |
|
| 52 | + * @since 0.1.0 |
|
| 53 | + * |
|
| 54 | + * @param ConfigInterface $config Configuration of the EngineFinder. |
|
| 55 | + * |
|
| 56 | + * @throws FailedToProcessConfigException If the config could not be processed. |
|
| 57 | + */ |
|
| 58 | + public function __construct(ConfigInterface $config) |
|
| 59 | + { |
|
| 60 | + $this->processConfig($config); |
|
| 61 | + $this->registerFindables($this->config); |
|
| 62 | + $this->registerNullObject($this->config); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Register the Findables defined in the given configuration. |
|
| 67 | - * |
|
| 68 | - * @since 0.1.0 |
|
| 69 | - * |
|
| 70 | - * @param ConfigInterface $config Configuration to register the Findables from. |
|
| 71 | - */ |
|
| 72 | - public function registerFindables(ConfigInterface $config) |
|
| 73 | - { |
|
| 74 | - foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) { |
|
| 75 | - $this->registerFindable($findableKey, $findableObject); |
|
| 76 | - } |
|
| 77 | - } |
|
| 65 | + /** |
|
| 66 | + * Register the Findables defined in the given configuration. |
|
| 67 | + * |
|
| 68 | + * @since 0.1.0 |
|
| 69 | + * |
|
| 70 | + * @param ConfigInterface $config Configuration to register the Findables from. |
|
| 71 | + */ |
|
| 72 | + public function registerFindables(ConfigInterface $config) |
|
| 73 | + { |
|
| 74 | + foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) { |
|
| 75 | + $this->registerFindable($findableKey, $findableObject); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Register the NullObject defined in the given configuration. |
|
| 81 | - * |
|
| 82 | - * @since 0.1.0 |
|
| 83 | - * |
|
| 84 | - * @param ConfigInterface $config Configuration to register the NullObject from. |
|
| 85 | - */ |
|
| 86 | - public function registerNullObject(ConfigInterface $config) |
|
| 87 | - { |
|
| 88 | - $this->nullObject = $config->getKey($this->getNullObjectConfigKey()); |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * Register the NullObject defined in the given configuration. |
|
| 81 | + * |
|
| 82 | + * @since 0.1.0 |
|
| 83 | + * |
|
| 84 | + * @param ConfigInterface $config Configuration to register the NullObject from. |
|
| 85 | + */ |
|
| 86 | + public function registerNullObject(ConfigInterface $config) |
|
| 87 | + { |
|
| 88 | + $this->nullObject = $config->getKey($this->getNullObjectConfigKey()); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get the NullObject. |
|
| 93 | - * |
|
| 94 | - * @since 0.1.1 |
|
| 95 | - * |
|
| 96 | - * @return NullObject NullObject for the current Finder. |
|
| 97 | - */ |
|
| 98 | - public function getNullObject() |
|
| 99 | - { |
|
| 100 | - $this->initializeNullObject(); |
|
| 91 | + /** |
|
| 92 | + * Get the NullObject. |
|
| 93 | + * |
|
| 94 | + * @since 0.1.1 |
|
| 95 | + * |
|
| 96 | + * @return NullObject NullObject for the current Finder. |
|
| 97 | + */ |
|
| 98 | + public function getNullObject() |
|
| 99 | + { |
|
| 100 | + $this->initializeNullObject(); |
|
| 101 | 101 | |
| 102 | - return $this->nullObject; |
|
| 103 | - } |
|
| 102 | + return $this->nullObject; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Register a single Findable. |
|
| 107 | - * |
|
| 108 | - * @since 0.1.0 |
|
| 109 | - * |
|
| 110 | - * @param string $key Key used to reference the Findable. |
|
| 111 | - * @param mixed $findable Findable as a FQCN, callable or object. |
|
| 112 | - */ |
|
| 113 | - protected function registerFindable($key, $findable) |
|
| 114 | - { |
|
| 115 | - $this->findables[$key] = $findable; |
|
| 116 | - } |
|
| 105 | + /** |
|
| 106 | + * Register a single Findable. |
|
| 107 | + * |
|
| 108 | + * @since 0.1.0 |
|
| 109 | + * |
|
| 110 | + * @param string $key Key used to reference the Findable. |
|
| 111 | + * @param mixed $findable Findable as a FQCN, callable or object. |
|
| 112 | + */ |
|
| 113 | + protected function registerFindable($key, $findable) |
|
| 114 | + { |
|
| 115 | + $this->findables[$key] = $findable; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Get the config key for the Findables definitions. |
|
| 120 | - * |
|
| 121 | - * @since 0.1.0 |
|
| 122 | - * |
|
| 123 | - * @return string Config key use to define the Findables. |
|
| 124 | - */ |
|
| 125 | - protected function getFindablesConfigKey() |
|
| 126 | - { |
|
| 127 | - return 'Findables'; |
|
| 128 | - } |
|
| 118 | + /** |
|
| 119 | + * Get the config key for the Findables definitions. |
|
| 120 | + * |
|
| 121 | + * @since 0.1.0 |
|
| 122 | + * |
|
| 123 | + * @return string Config key use to define the Findables. |
|
| 124 | + */ |
|
| 125 | + protected function getFindablesConfigKey() |
|
| 126 | + { |
|
| 127 | + return 'Findables'; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Get the config key for the NullObject definitions. |
|
| 132 | - * |
|
| 133 | - * @since 0.1.0 |
|
| 134 | - * |
|
| 135 | - * @return string Config key use to define the NullObject. |
|
| 136 | - */ |
|
| 137 | - protected function getNullObjectConfigKey() |
|
| 138 | - { |
|
| 139 | - return 'NullObject'; |
|
| 140 | - } |
|
| 130 | + /** |
|
| 131 | + * Get the config key for the NullObject definitions. |
|
| 132 | + * |
|
| 133 | + * @since 0.1.0 |
|
| 134 | + * |
|
| 135 | + * @return string Config key use to define the NullObject. |
|
| 136 | + */ |
|
| 137 | + protected function getNullObjectConfigKey() |
|
| 138 | + { |
|
| 139 | + return 'NullObject'; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Initialize the NullObject. |
|
| 144 | - * |
|
| 145 | - * @since 0.1.1 |
|
| 146 | - */ |
|
| 147 | - protected function initializeNullObject() |
|
| 148 | - { |
|
| 149 | - if (! is_object($this->nullObject)) { |
|
| 150 | - $this->nullObject = new $this->nullObject(); |
|
| 151 | - } |
|
| 152 | - } |
|
| 142 | + /** |
|
| 143 | + * Initialize the NullObject. |
|
| 144 | + * |
|
| 145 | + * @since 0.1.1 |
|
| 146 | + */ |
|
| 147 | + protected function initializeNullObject() |
|
| 148 | + { |
|
| 149 | + if (! is_object($this->nullObject)) { |
|
| 150 | + $this->nullObject = new $this->nullObject(); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -24,20 +24,20 @@ |
||
| 24 | 24 | class NullView implements ViewInterface, NullObject |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Render the view. |
|
| 29 | - * |
|
| 30 | - * @since 0.1.0 |
|
| 31 | - * |
|
| 32 | - * @param array $context Optional. The context in which to render the view. |
|
| 33 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
| 34 | - * |
|
| 35 | - * @return string|void Rendered HTML or nothing, depending on $echo argument. |
|
| 36 | - */ |
|
| 37 | - public function render(array $context = [], $echo = false) |
|
| 38 | - { |
|
| 39 | - if (! $echo) { |
|
| 40 | - return ''; |
|
| 41 | - } |
|
| 42 | - } |
|
| 27 | + /** |
|
| 28 | + * Render the view. |
|
| 29 | + * |
|
| 30 | + * @since 0.1.0 |
|
| 31 | + * |
|
| 32 | + * @param array $context Optional. The context in which to render the view. |
|
| 33 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
| 34 | + * |
|
| 35 | + * @return string|void Rendered HTML or nothing, depending on $echo argument. |
|
| 36 | + */ |
|
| 37 | + public function render(array $context = [], $echo = false) |
|
| 38 | + { |
|
| 39 | + if (! $echo) { |
|
| 40 | + return ''; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | public function render(array $context = [], $echo = false) |
| 38 | 38 | { |
| 39 | - if (! $echo) { |
|
| 39 | + if ( ! $echo) { |
|
| 40 | 40 | return ''; |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -25,15 +25,15 @@ |
||
| 25 | 25 | interface ViewFinderInterface extends FinderInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Find a result based on a specific criteria. |
|
| 30 | - * |
|
| 31 | - * @since 0.1.0 |
|
| 32 | - * |
|
| 33 | - * @param array $criteria Criteria to search for. |
|
| 34 | - * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
| 35 | - * |
|
| 36 | - * @return ViewInterface View that was found. |
|
| 37 | - */ |
|
| 38 | - public function find(array $criteria, EngineInterface $engine = null); |
|
| 28 | + /** |
|
| 29 | + * Find a result based on a specific criteria. |
|
| 30 | + * |
|
| 31 | + * @since 0.1.0 |
|
| 32 | + * |
|
| 33 | + * @param array $criteria Criteria to search for. |
|
| 34 | + * @param EngineInterface|null $engine Optional. Engine to use with the view. |
|
| 35 | + * |
|
| 36 | + * @return ViewInterface View that was found. |
|
| 37 | + */ |
|
| 38 | + public function find(array $criteria, EngineInterface $engine = null); |
|
| 39 | 39 | } |
@@ -22,25 +22,25 @@ |
||
| 22 | 22 | interface LocationInterface |
| 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 array URI that matches the criteria or false if none found. |
|
| 44 | - */ |
|
| 45 | - public function getURIs(array $criteria); |
|
| 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 array URI that matches the criteria or false if none found. |
|
| 44 | + */ |
|
| 45 | + public function getURIs(array $criteria); |
|
| 46 | 46 | } |
@@ -24,131 +24,131 @@ |
||
| 24 | 24 | class FilesystemLocation implements LocationInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Path that this location points to. |
|
| 29 | - * |
|
| 30 | - * @since 0.1.0 |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $path; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Extensions that this location can accept. |
|
| 38 | - * |
|
| 39 | - * @since 0.1.0 |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $extensions; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Instantiate a FilesystemLocation object. |
|
| 47 | - * |
|
| 48 | - * @since 0.1.0 |
|
| 49 | - * |
|
| 50 | - * @param string $path Path that this location points to. |
|
| 51 | - * @param array $extensions Array of extensions that this location can accept. |
|
| 52 | - */ |
|
| 53 | - public function __construct($path, array $extensions = []) |
|
| 54 | - { |
|
| 55 | - $this->path = $path; |
|
| 56 | - $this->extensions = array_merge($extensions, ['']); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Get the first URI that matches the given criteria. |
|
| 61 | - * |
|
| 62 | - * @since 0.1.0 |
|
| 63 | - * |
|
| 64 | - * @param array $criteria Criteria to match. |
|
| 65 | - * |
|
| 66 | - * @return string|false URI that matches the criteria or false if none found. |
|
| 67 | - */ |
|
| 68 | - public function getURI(array $criteria) |
|
| 69 | - { |
|
| 70 | - foreach ($criteria as $entry) { |
|
| 71 | - if ($uri = $this->transform($entry, true)) { |
|
| 72 | - return $uri; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Get all URIs that match the given criteria. |
|
| 81 | - * |
|
| 82 | - * @since 0.1.1 |
|
| 83 | - * |
|
| 84 | - * @param array $criteria Criteria to match. |
|
| 85 | - * |
|
| 86 | - * @return array URIs that match the criteria or empty array if none found. |
|
| 87 | - */ |
|
| 88 | - public function getURIs(array $criteria) |
|
| 89 | - { |
|
| 90 | - $uris = []; |
|
| 91 | - |
|
| 92 | - foreach ($criteria as $entry) { |
|
| 93 | - if ($uri = $this->transform($entry, false)) { |
|
| 94 | - $uris = array_merge($uris, (array)$uri); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $uris; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Try to transform the entry into possible URIs. |
|
| 103 | - * |
|
| 104 | - * @since 0.1.0 |
|
| 105 | - * |
|
| 106 | - * @param string $entry Entry to transform. |
|
| 107 | - * @param bool $firstOnly Return the first result only. |
|
| 108 | - * |
|
| 109 | - * @return array|string|false If $firstOnly is true, returns a string with the URI of the view, or false if none |
|
| 110 | - * found. |
|
| 111 | - * If $firstOnly is false, returns an array with all matching URIs, or an empty array if |
|
| 112 | - * none found. |
|
| 113 | - */ |
|
| 114 | - protected function transform($entry, $firstOnly = true) |
|
| 115 | - { |
|
| 116 | - $uris = []; |
|
| 117 | - |
|
| 118 | - try { |
|
| 119 | - foreach ($this->getVariants($entry) as $uri) { |
|
| 120 | - if (is_readable($uri)) { |
|
| 121 | - if ($firstOnly) { |
|
| 122 | - return $uri; |
|
| 123 | - } |
|
| 124 | - $uris [] = $uri; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } catch (Exception $exception) { |
|
| 128 | - // Fail silently. |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $firstOnly ? false : $uris; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Get the individual variants that could be matched for the location. |
|
| 136 | - * |
|
| 137 | - * @since 0.1.1 |
|
| 138 | - * |
|
| 139 | - * @param string $entry Entry to get the variants for. |
|
| 140 | - * |
|
| 141 | - * @return array Array of variants to check. |
|
| 142 | - */ |
|
| 143 | - protected function getVariants($entry) |
|
| 144 | - { |
|
| 145 | - $variants = []; |
|
| 146 | - |
|
| 147 | - array_map(function ($extension) use ($entry, &$variants) { |
|
| 148 | - $variants[] = $entry . $extension; |
|
| 149 | - $variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension; |
|
| 150 | - }, $this->extensions); |
|
| 151 | - |
|
| 152 | - return $variants; |
|
| 153 | - } |
|
| 27 | + /** |
|
| 28 | + * Path that this location points to. |
|
| 29 | + * |
|
| 30 | + * @since 0.1.0 |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $path; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Extensions that this location can accept. |
|
| 38 | + * |
|
| 39 | + * @since 0.1.0 |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $extensions; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Instantiate a FilesystemLocation object. |
|
| 47 | + * |
|
| 48 | + * @since 0.1.0 |
|
| 49 | + * |
|
| 50 | + * @param string $path Path that this location points to. |
|
| 51 | + * @param array $extensions Array of extensions that this location can accept. |
|
| 52 | + */ |
|
| 53 | + public function __construct($path, array $extensions = []) |
|
| 54 | + { |
|
| 55 | + $this->path = $path; |
|
| 56 | + $this->extensions = array_merge($extensions, ['']); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Get the first URI that matches the given criteria. |
|
| 61 | + * |
|
| 62 | + * @since 0.1.0 |
|
| 63 | + * |
|
| 64 | + * @param array $criteria Criteria to match. |
|
| 65 | + * |
|
| 66 | + * @return string|false URI that matches the criteria or false if none found. |
|
| 67 | + */ |
|
| 68 | + public function getURI(array $criteria) |
|
| 69 | + { |
|
| 70 | + foreach ($criteria as $entry) { |
|
| 71 | + if ($uri = $this->transform($entry, true)) { |
|
| 72 | + return $uri; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Get all URIs that match the given criteria. |
|
| 81 | + * |
|
| 82 | + * @since 0.1.1 |
|
| 83 | + * |
|
| 84 | + * @param array $criteria Criteria to match. |
|
| 85 | + * |
|
| 86 | + * @return array URIs that match the criteria or empty array if none found. |
|
| 87 | + */ |
|
| 88 | + public function getURIs(array $criteria) |
|
| 89 | + { |
|
| 90 | + $uris = []; |
|
| 91 | + |
|
| 92 | + foreach ($criteria as $entry) { |
|
| 93 | + if ($uri = $this->transform($entry, false)) { |
|
| 94 | + $uris = array_merge($uris, (array)$uri); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $uris; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Try to transform the entry into possible URIs. |
|
| 103 | + * |
|
| 104 | + * @since 0.1.0 |
|
| 105 | + * |
|
| 106 | + * @param string $entry Entry to transform. |
|
| 107 | + * @param bool $firstOnly Return the first result only. |
|
| 108 | + * |
|
| 109 | + * @return array|string|false If $firstOnly is true, returns a string with the URI of the view, or false if none |
|
| 110 | + * found. |
|
| 111 | + * If $firstOnly is false, returns an array with all matching URIs, or an empty array if |
|
| 112 | + * none found. |
|
| 113 | + */ |
|
| 114 | + protected function transform($entry, $firstOnly = true) |
|
| 115 | + { |
|
| 116 | + $uris = []; |
|
| 117 | + |
|
| 118 | + try { |
|
| 119 | + foreach ($this->getVariants($entry) as $uri) { |
|
| 120 | + if (is_readable($uri)) { |
|
| 121 | + if ($firstOnly) { |
|
| 122 | + return $uri; |
|
| 123 | + } |
|
| 124 | + $uris [] = $uri; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } catch (Exception $exception) { |
|
| 128 | + // Fail silently. |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $firstOnly ? false : $uris; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Get the individual variants that could be matched for the location. |
|
| 136 | + * |
|
| 137 | + * @since 0.1.1 |
|
| 138 | + * |
|
| 139 | + * @param string $entry Entry to get the variants for. |
|
| 140 | + * |
|
| 141 | + * @return array Array of variants to check. |
|
| 142 | + */ |
|
| 143 | + protected function getVariants($entry) |
|
| 144 | + { |
|
| 145 | + $variants = []; |
|
| 146 | + |
|
| 147 | + array_map(function ($extension) use ($entry, &$variants) { |
|
| 148 | + $variants[] = $entry . $extension; |
|
| 149 | + $variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension; |
|
| 150 | + }, $this->extensions); |
|
| 151 | + |
|
| 152 | + return $variants; |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | foreach ($criteria as $entry) { |
| 93 | 93 | if ($uri = $this->transform($entry, false)) { |
| 94 | - $uris = array_merge($uris, (array)$uri); |
|
| 94 | + $uris = array_merge($uris, (array) $uri); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | { |
| 145 | 145 | $variants = []; |
| 146 | 146 | |
| 147 | - array_map(function ($extension) use ($entry, &$variants) { |
|
| 148 | - $variants[] = $entry . $extension; |
|
| 149 | - $variants[] = $this->path . DIRECTORY_SEPARATOR . $entry . $extension; |
|
| 147 | + array_map(function($extension) use ($entry, &$variants) { |
|
| 148 | + $variants[] = $entry.$extension; |
|
| 149 | + $variants[] = $this->path.DIRECTORY_SEPARATOR.$entry.$extension; |
|
| 150 | 150 | }, $this->extensions); |
| 151 | 151 | |
| 152 | 152 | return $variants; |