@@ -25,15 +25,15 @@ |
||
25 | 25 | interface ViewFinder extends Finder |
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 Engine|null $engine Optional. Engine to use with the view. |
|
35 | - * |
|
36 | - * @return View View that was found. |
|
37 | - */ |
|
38 | - public function find(array $criteria, Engine $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 Engine|null $engine Optional. Engine to use with the view. |
|
35 | + * |
|
36 | + * @return View View that was found. |
|
37 | + */ |
|
38 | + public function find(array $criteria, Engine $engine = null); |
|
39 | 39 | } |
@@ -26,42 +26,42 @@ |
||
26 | 26 | class BaseViewFinder extends AbstractFinder |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Find a result based on a specific criteria. |
|
31 | - * |
|
32 | - * @since 0.1.0 |
|
33 | - * |
|
34 | - * @param array $criteria Criteria to search for. |
|
35 | - * @param Engine|null $engine Optional. Engine to use with the view. |
|
36 | - * |
|
37 | - * @return View View that was found. |
|
38 | - */ |
|
39 | - public function find(array $criteria, Engine $engine = null) |
|
40 | - { |
|
41 | - $uri = $criteria[0]; |
|
29 | + /** |
|
30 | + * Find a result based on a specific criteria. |
|
31 | + * |
|
32 | + * @since 0.1.0 |
|
33 | + * |
|
34 | + * @param array $criteria Criteria to search for. |
|
35 | + * @param Engine|null $engine Optional. Engine to use with the view. |
|
36 | + * |
|
37 | + * @return View View that was found. |
|
38 | + */ |
|
39 | + public function find(array $criteria, Engine $engine = null) |
|
40 | + { |
|
41 | + $uri = $criteria[0]; |
|
42 | 42 | |
43 | - $this->initializeFindables([$uri, $engine]); |
|
43 | + $this->initializeFindables([$uri, $engine]); |
|
44 | 44 | |
45 | - foreach ($criteria as $entry) { |
|
46 | - foreach ($this->findables as $viewObject) { |
|
47 | - if ($viewObject->canHandle($entry)) { |
|
48 | - return $viewObject; |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
45 | + foreach ($criteria as $entry) { |
|
46 | + foreach ($this->findables as $viewObject) { |
|
47 | + if ($viewObject->canHandle($entry)) { |
|
48 | + return $viewObject; |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - return $this->getNullObject(); |
|
54 | - } |
|
53 | + return $this->getNullObject(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get the config key for the Findables definitions. |
|
58 | - * |
|
59 | - * @since 0.1.0 |
|
60 | - * |
|
61 | - * @return string Config key use to define the Findables. |
|
62 | - */ |
|
63 | - protected function getFindablesConfigKey() |
|
64 | - { |
|
65 | - return 'Views'; |
|
66 | - } |
|
56 | + /** |
|
57 | + * Get the config key for the Findables definitions. |
|
58 | + * |
|
59 | + * @since 0.1.0 |
|
60 | + * |
|
61 | + * @return string Config key use to define the Findables. |
|
62 | + */ |
|
63 | + protected function getFindablesConfigKey() |
|
64 | + { |
|
65 | + return 'Views'; |
|
66 | + } |
|
67 | 67 | } |
@@ -24,49 +24,49 @@ |
||
24 | 24 | interface View extends Findable |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Check whether the Findable can handle an individual criterion. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param mixed $criterion Criterion to check. |
|
33 | - * |
|
34 | - * @return bool Whether the Findable can handle the criterion. |
|
35 | - */ |
|
36 | - public function canHandle($criterion); |
|
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 | 37 | |
38 | - /** |
|
39 | - * Render the view. |
|
40 | - * |
|
41 | - * @since 0.1.0 |
|
42 | - * |
|
43 | - * @param array $context Optional. The context in which to render the view. |
|
44 | - * |
|
45 | - * @return string Rendered HTML. |
|
46 | - */ |
|
47 | - public function render(array $context = []); |
|
38 | + /** |
|
39 | + * Render the view. |
|
40 | + * |
|
41 | + * @since 0.1.0 |
|
42 | + * |
|
43 | + * @param array $context Optional. The context in which to render the view. |
|
44 | + * |
|
45 | + * @return string Rendered HTML. |
|
46 | + */ |
|
47 | + public function render(array $context = []); |
|
48 | 48 | |
49 | - /** |
|
50 | - * Render a partial view for a given URI. |
|
51 | - * |
|
52 | - * @since 0.2.0 |
|
53 | - * |
|
54 | - * @param string $view View identifier to create a view for. |
|
55 | - * @param array $context Optional. The context in which to render the view. |
|
56 | - * @param string|null $type Type of view to create. |
|
57 | - * |
|
58 | - * @return string Rendered HTML content. |
|
59 | - */ |
|
60 | - public function renderPart($view, array $context = [], $type = null); |
|
49 | + /** |
|
50 | + * Render a partial view for a given URI. |
|
51 | + * |
|
52 | + * @since 0.2.0 |
|
53 | + * |
|
54 | + * @param string $view View identifier to create a view for. |
|
55 | + * @param array $context Optional. The context in which to render the view. |
|
56 | + * @param string|null $type Type of view to create. |
|
57 | + * |
|
58 | + * @return string Rendered HTML content. |
|
59 | + */ |
|
60 | + public function renderPart($view, array $context = [], $type = null); |
|
61 | 61 | |
62 | - /** |
|
63 | - * Associate a view builder with this view. |
|
64 | - * |
|
65 | - * @since 0.2.0 |
|
66 | - * |
|
67 | - * @param ViewBuilder $builder |
|
68 | - * |
|
69 | - * @return static |
|
70 | - */ |
|
71 | - public function setBuilder(ViewBuilder $builder); |
|
62 | + /** |
|
63 | + * Associate a view builder with this view. |
|
64 | + * |
|
65 | + * @since 0.2.0 |
|
66 | + * |
|
67 | + * @param ViewBuilder $builder |
|
68 | + * |
|
69 | + * @return static |
|
70 | + */ |
|
71 | + public function setBuilder(ViewBuilder $builder); |
|
72 | 72 | } |
@@ -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 static New URIs instance. |
|
36 | - */ |
|
37 | - public static function fromFinder(Finder $finder) |
|
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 static New URIs instance. |
|
36 | + */ |
|
37 | + public static function fromFinder(Finder $finder) |
|
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($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) |
|
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, $extension) |
|
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() |
|
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) |
|
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) |
|
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($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) |
|
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, $extension) |
|
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() |
|
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) |
|
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) |
|
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 | } |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | { |
125 | 125 | $names = []; |
126 | 126 | |
127 | - $names[] = array_map(function ($criterion) use ($extension) { |
|
127 | + $names[] = array_map(function($criterion) use ($extension) { |
|
128 | 128 | $criterion = URIHelper::getFilename($criterion); |
129 | 129 | |
130 | 130 | return empty($extension) || URIHelper::hasExtension($criterion, $extension) |
131 | 131 | ? $criterion |
132 | - : $criterion . $extension; |
|
132 | + : $criterion.$extension; |
|
133 | 133 | }, $criteria)[0]; |
134 | 134 | |
135 | 135 | return $this->arrayToRegexPattern(array_unique($names)); |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | */ |
159 | 159 | protected function arrayToRegexPattern(array $array) |
160 | 160 | { |
161 | - $array = array_map(function ($entry) { |
|
161 | + $array = array_map(function($entry) { |
|
162 | 162 | return preg_quote($entry); |
163 | 163 | }, $array); |
164 | 164 | |
165 | - return '/' . implode('|', $array) . '/'; |
|
165 | + return '/'.implode('|', $array).'/'; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | } |
182 | 182 | |
183 | 183 | if ( ! $extensions instanceof Extensions) { |
184 | - $extensions = new Extensions((array)$extensions); |
|
184 | + $extensions = new Extensions((array) $extensions); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | return $extensions; |
@@ -25,48 +25,48 @@ |
||
25 | 25 | class Locations extends ArrayCollection |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Adds a location at the end of the collection if it does not already exist. |
|
30 | - * |
|
31 | - * @param mixed $location The location to add. |
|
32 | - * |
|
33 | - * @return boolean Whether the location was added or not. |
|
34 | - */ |
|
35 | - public function add($location) |
|
36 | - { |
|
37 | - if ($this->hasLocation($location)) { |
|
38 | - return false; |
|
39 | - } |
|
28 | + /** |
|
29 | + * Adds a location at the end of the collection if it does not already exist. |
|
30 | + * |
|
31 | + * @param mixed $location The location to add. |
|
32 | + * |
|
33 | + * @return boolean Whether the location was added or not. |
|
34 | + */ |
|
35 | + public function add($location) |
|
36 | + { |
|
37 | + if ($this->hasLocation($location)) { |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | - return parent::add($location); |
|
42 | - } |
|
41 | + return parent::add($location); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Check whether a given location is already registered. |
|
46 | - * |
|
47 | - * For two locations to be equal, both their path and their extensions must be the same. |
|
48 | - * |
|
49 | - * @since 0.1.1 |
|
50 | - * |
|
51 | - * @param Location $location Location to check the existence of. |
|
52 | - * |
|
53 | - * @return bool Whether the location is already registered or not. |
|
54 | - * |
|
55 | - * @throws InvalidLocation If the location is not valid. |
|
56 | - */ |
|
57 | - public function hasLocation($location) |
|
58 | - { |
|
59 | - if ( ! $location instanceof Location) { |
|
60 | - throw new InvalidLocation( |
|
61 | - sprintf( |
|
62 | - _('Invalid location to check existence for: "%s".'), |
|
63 | - serialize($location) |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
44 | + /** |
|
45 | + * Check whether a given location is already registered. |
|
46 | + * |
|
47 | + * For two locations to be equal, both their path and their extensions must be the same. |
|
48 | + * |
|
49 | + * @since 0.1.1 |
|
50 | + * |
|
51 | + * @param Location $location Location to check the existence of. |
|
52 | + * |
|
53 | + * @return bool Whether the location is already registered or not. |
|
54 | + * |
|
55 | + * @throws InvalidLocation If the location is not valid. |
|
56 | + */ |
|
57 | + public function hasLocation($location) |
|
58 | + { |
|
59 | + if ( ! $location instanceof Location) { |
|
60 | + throw new InvalidLocation( |
|
61 | + sprintf( |
|
62 | + _('Invalid location to check existence for: "%s".'), |
|
63 | + serialize($location) |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | |
68 | - return $this->exists(function ($key, $element) use ($location) { |
|
69 | - return $location == $element; |
|
70 | - }); |
|
71 | - } |
|
68 | + return $this->exists(function ($key, $element) use ($location) { |
|
69 | + return $location == $element; |
|
70 | + }); |
|
71 | + } |
|
72 | 72 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - return $this->exists(function ($key, $element) use ($location) { |
|
68 | + return $this->exists(function($key, $element) use ($location) { |
|
69 | 69 | return $location == $element; |
70 | 70 | }); |
71 | 71 | } |
@@ -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); |
|
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); |
|
46 | 46 | } |
@@ -27,91 +27,91 @@ |
||
27 | 27 | class Views |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * ViewBuilder Instance. |
|
32 | - * |
|
33 | - * @since 0.1.0 |
|
34 | - * |
|
35 | - * @var ViewBuilder |
|
36 | - */ |
|
37 | - protected static $viewBuilder; |
|
30 | + /** |
|
31 | + * ViewBuilder Instance. |
|
32 | + * |
|
33 | + * @since 0.1.0 |
|
34 | + * |
|
35 | + * @var ViewBuilder |
|
36 | + */ |
|
37 | + protected static $viewBuilder; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Add a location to the ViewBuilder. |
|
41 | - * |
|
42 | - * @since 0.1.0 |
|
43 | - * |
|
44 | - * @param Location $location Location to add. |
|
45 | - */ |
|
46 | - public static function addLocation(Location $location) |
|
47 | - { |
|
48 | - $viewBuilder = static::getViewBuilder(); |
|
49 | - $viewBuilder->addLocation($location); |
|
50 | - } |
|
39 | + /** |
|
40 | + * Add a location to the ViewBuilder. |
|
41 | + * |
|
42 | + * @since 0.1.0 |
|
43 | + * |
|
44 | + * @param Location $location Location to add. |
|
45 | + */ |
|
46 | + public static function addLocation(Location $location) |
|
47 | + { |
|
48 | + $viewBuilder = static::getViewBuilder(); |
|
49 | + $viewBuilder->addLocation($location); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the ViewBuilder instance. |
|
54 | - * |
|
55 | - * @since 0.1.0 |
|
56 | - * |
|
57 | - * @return ViewBuilder |
|
58 | - */ |
|
59 | - public static function getViewBuilder() |
|
60 | - { |
|
61 | - if (null === static::$viewBuilder) { |
|
62 | - static::$viewBuilder = static::instantiateViewBuilder(); |
|
63 | - } |
|
52 | + /** |
|
53 | + * Get the ViewBuilder instance. |
|
54 | + * |
|
55 | + * @since 0.1.0 |
|
56 | + * |
|
57 | + * @return ViewBuilder |
|
58 | + */ |
|
59 | + public static function getViewBuilder() |
|
60 | + { |
|
61 | + if (null === static::$viewBuilder) { |
|
62 | + static::$viewBuilder = static::instantiateViewBuilder(); |
|
63 | + } |
|
64 | 64 | |
65 | - return static::$viewBuilder; |
|
66 | - } |
|
65 | + return static::$viewBuilder; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Instantiate the ViewBuilder. |
|
70 | - * |
|
71 | - * @since 0.1.0 |
|
72 | - * |
|
73 | - * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
74 | - * |
|
75 | - * @return ViewBuilder Instance of the ViewBuilder. |
|
76 | - */ |
|
77 | - public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
78 | - { |
|
79 | - return static::$viewBuilder = new ViewBuilder($config); |
|
80 | - } |
|
68 | + /** |
|
69 | + * Instantiate the ViewBuilder. |
|
70 | + * |
|
71 | + * @since 0.1.0 |
|
72 | + * |
|
73 | + * @param ConfigInterface|null $config Optional. Configuration to pass into the ViewBuilder. |
|
74 | + * |
|
75 | + * @return ViewBuilder Instance of the ViewBuilder. |
|
76 | + */ |
|
77 | + public static function instantiateViewBuilder(ConfigInterface $config = null) |
|
78 | + { |
|
79 | + return static::$viewBuilder = new ViewBuilder($config); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Create a new view for a given URI. |
|
84 | - * |
|
85 | - * @since 0.1.0 |
|
86 | - * |
|
87 | - * @param string $view View identifier to create a view for. |
|
88 | - * @param string|null $type Type of view to create. |
|
89 | - * |
|
90 | - * @return View Instance of the requested view. |
|
91 | - */ |
|
92 | - public static function create($view, $type = null) |
|
93 | - { |
|
94 | - $viewBuilder = static::getViewBuilder(); |
|
82 | + /** |
|
83 | + * Create a new view for a given URI. |
|
84 | + * |
|
85 | + * @since 0.1.0 |
|
86 | + * |
|
87 | + * @param string $view View identifier to create a view for. |
|
88 | + * @param string|null $type Type of view to create. |
|
89 | + * |
|
90 | + * @return View Instance of the requested view. |
|
91 | + */ |
|
92 | + public static function create($view, $type = null) |
|
93 | + { |
|
94 | + $viewBuilder = static::getViewBuilder(); |
|
95 | 95 | |
96 | - return $viewBuilder->create($view, $type); |
|
97 | - } |
|
96 | + return $viewBuilder->create($view, $type); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Render a view for a given URI. |
|
101 | - * |
|
102 | - * @since 0.1.0 |
|
103 | - * |
|
104 | - * @param string $view View identifier to create a view for. |
|
105 | - * @param array $context Optional. The context in which to render the view. |
|
106 | - * @param string|null $type Type of view to create. |
|
107 | - * |
|
108 | - * @return string Rendered HTML content. |
|
109 | - */ |
|
110 | - public static function render($view, array $context = [], $type = null) |
|
111 | - { |
|
112 | - $viewBuilder = static::getViewBuilder(); |
|
113 | - $viewObject = $viewBuilder->create($view, $type); |
|
99 | + /** |
|
100 | + * Render a view for a given URI. |
|
101 | + * |
|
102 | + * @since 0.1.0 |
|
103 | + * |
|
104 | + * @param string $view View identifier to create a view for. |
|
105 | + * @param array $context Optional. The context in which to render the view. |
|
106 | + * @param string|null $type Type of view to create. |
|
107 | + * |
|
108 | + * @return string Rendered HTML content. |
|
109 | + */ |
|
110 | + public static function render($view, array $context = [], $type = null) |
|
111 | + { |
|
112 | + $viewBuilder = static::getViewBuilder(); |
|
113 | + $viewObject = $viewBuilder->create($view, $type); |
|
114 | 114 | |
115 | - return $viewObject->render($context); |
|
116 | - } |
|
115 | + return $viewObject->render($context); |
|
116 | + } |
|
117 | 117 | } |
@@ -12,26 +12,26 @@ |
||
12 | 12 | namespace BrightNucleus\View; |
13 | 13 | |
14 | 14 | $engineFinder = [ |
15 | - 'ClassName' => 'BrightNucleus\View\Engine\BaseEngineFinder', |
|
16 | - 'Engines' => [ |
|
17 | - 'PHPEngine' => 'BrightNucleus\View\Engine\PHPEngine', |
|
18 | - ], |
|
19 | - 'NullObject' => 'BrightNucleus\View\Engine\NullEngine', |
|
15 | + 'ClassName' => 'BrightNucleus\View\Engine\BaseEngineFinder', |
|
16 | + 'Engines' => [ |
|
17 | + 'PHPEngine' => 'BrightNucleus\View\Engine\PHPEngine', |
|
18 | + ], |
|
19 | + 'NullObject' => 'BrightNucleus\View\Engine\NullEngine', |
|
20 | 20 | ]; |
21 | 21 | |
22 | 22 | $viewFinder = [ |
23 | - 'ClassName' => 'BrightNucleus\View\View\BaseViewFinder', |
|
24 | - 'Views' => [ |
|
25 | - 'BaseView' => 'BrightNucleus\View\View\BaseView', |
|
26 | - ], |
|
27 | - 'NullObject' => 'BrightNucleus\View\View\NullView', |
|
23 | + 'ClassName' => 'BrightNucleus\View\View\BaseViewFinder', |
|
24 | + 'Views' => [ |
|
25 | + 'BaseView' => 'BrightNucleus\View\View\BaseView', |
|
26 | + ], |
|
27 | + 'NullObject' => 'BrightNucleus\View\View\NullView', |
|
28 | 28 | ]; |
29 | 29 | |
30 | 30 | return [ |
31 | - 'BrightNucleus' => [ |
|
32 | - 'View' => [ |
|
33 | - 'EngineFinder' => $engineFinder, |
|
34 | - 'ViewFinder' => $viewFinder, |
|
35 | - ], |
|
36 | - ], |
|
31 | + 'BrightNucleus' => [ |
|
32 | + 'View' => [ |
|
33 | + 'EngineFinder' => $engineFinder, |
|
34 | + 'ViewFinder' => $viewFinder, |
|
35 | + ], |
|
36 | + ], |
|
37 | 37 | ]; |