@@ -24,117 +24,117 @@ |
||
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; |
|
27 | + /** |
|
28 | + * Path that this location points to. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $path; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Extensions that this location can accept. |
|
38 | - * |
|
39 | - * @since 0.1.0 |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $extensions; |
|
36 | + /** |
|
37 | + * Extensions that this location can accept. |
|
38 | + * |
|
39 | + * @since 0.1.0 |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $extensions; |
|
44 | 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 | - } |
|
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 | 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 | - } |
|
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 | 75 | |
76 | - return false; |
|
77 | - } |
|
76 | + return false; |
|
77 | + } |
|
78 | 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 = []; |
|
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 | 91 | |
92 | - foreach ($criteria as $entry) { |
|
93 | - if ($uri = $this->transform($entry, false)) { |
|
94 | - $uris = array_merge($uris, (array)$uri); |
|
95 | - } |
|
96 | - } |
|
92 | + foreach ($criteria as $entry) { |
|
93 | + if ($uri = $this->transform($entry, false)) { |
|
94 | + $uris = array_merge($uris, (array)$uri); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $uris; |
|
99 | - } |
|
98 | + return $uris; |
|
99 | + } |
|
100 | 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 | - try { |
|
118 | - foreach ($this->extensions as $extension) { |
|
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 | + try { |
|
118 | + foreach ($this->extensions as $extension) { |
|
119 | 119 | |
120 | - $variants = [ |
|
121 | - $entry . $extension, |
|
122 | - $this->path . DIRECTORY_SEPARATOR . $entry . $extension, |
|
123 | - ]; |
|
120 | + $variants = [ |
|
121 | + $entry . $extension, |
|
122 | + $this->path . DIRECTORY_SEPARATOR . $entry . $extension, |
|
123 | + ]; |
|
124 | 124 | |
125 | - foreach ($variants as $uri) { |
|
126 | - if (is_readable($uri)) { |
|
127 | - if ($firstOnly) { |
|
128 | - return $uri; |
|
129 | - } |
|
130 | - $uris [] = $uri; |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - } catch (Exception $exception) { |
|
135 | - // Fail silently. |
|
136 | - } |
|
125 | + foreach ($variants as $uri) { |
|
126 | + if (is_readable($uri)) { |
|
127 | + if ($firstOnly) { |
|
128 | + return $uri; |
|
129 | + } |
|
130 | + $uris [] = $uri; |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + } catch (Exception $exception) { |
|
135 | + // Fail silently. |
|
136 | + } |
|
137 | 137 | |
138 | - return $firstOnly ? false : $uris; |
|
139 | - } |
|
138 | + return $firstOnly ? false : $uris; |
|
139 | + } |
|
140 | 140 | } |
@@ -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 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | foreach ($this->extensions as $extension) { |
119 | 119 | |
120 | 120 | $variants = [ |
121 | - $entry . $extension, |
|
122 | - $this->path . DIRECTORY_SEPARATOR . $entry . $extension, |
|
121 | + $entry.$extension, |
|
122 | + $this->path.DIRECTORY_SEPARATOR.$entry.$extension, |
|
123 | 123 | ]; |
124 | 124 | |
125 | 125 | foreach ($variants as $uri) { |
@@ -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 | } |