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