@@ -30,174 +30,174 @@ |
||
30 | 30 | abstract class AbstractView implements View |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * URI of the view. |
|
35 | - * |
|
36 | - * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
37 | - * |
|
38 | - * @since 0.1.0 |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_uri_; |
|
43 | - |
|
44 | - /** |
|
45 | - * Engine to use for the view. |
|
46 | - * |
|
47 | - * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
48 | - * |
|
49 | - * @since 0.1.0 |
|
50 | - * |
|
51 | - * @var Engine |
|
52 | - */ |
|
53 | - protected $_engine_; |
|
54 | - |
|
55 | - /** |
|
56 | - * ViewBuilder instance. |
|
57 | - * |
|
58 | - * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
59 | - * |
|
60 | - * @since 0.2.0 |
|
61 | - * |
|
62 | - * @var ViewBuilder |
|
63 | - */ |
|
64 | - protected $_builder_; |
|
65 | - |
|
66 | - /** |
|
67 | - * The context with which the view will be rendered. |
|
68 | - * |
|
69 | - * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
70 | - * |
|
71 | - * @since 0.4.0 |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - protected $_context_ = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * Instantiate an AbstractView object. |
|
79 | - * |
|
80 | - * @since 0.1.0 |
|
81 | - * |
|
82 | - * @param string $uri URI for the view. |
|
83 | - * @param Engine $engine Engine to use for the view. |
|
84 | - */ |
|
85 | - public function __construct(string $uri, Engine $engine) |
|
86 | - { |
|
87 | - $this->_uri_ = $uri; |
|
88 | - $this->_engine_ = $engine; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Render the view. |
|
93 | - * |
|
94 | - * @since 0.1.0 |
|
95 | - * |
|
96 | - * @param array $context Optional. The context in which to render the view. |
|
97 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
98 | - * |
|
99 | - * @return string Rendered HTML. |
|
100 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
101 | - */ |
|
102 | - public function render(array $context = [], bool $echo = false): string |
|
103 | - { |
|
104 | - $this->initializeViewBuilder(); |
|
105 | - $this->assimilateContext($context); |
|
106 | - |
|
107 | - $closure = Closure::bind( |
|
108 | - $this->_engine_->getRenderCallback($this->_uri_, $context), |
|
109 | - $this, |
|
110 | - static::class |
|
111 | - ); |
|
112 | - |
|
113 | - $output = $closure(); |
|
114 | - |
|
115 | - if ($echo) { |
|
116 | - echo $output; |
|
117 | - } |
|
118 | - |
|
119 | - return $output; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Render a partial view (or section) for a given URI. |
|
124 | - * |
|
125 | - * @since 0.2.0 |
|
126 | - * |
|
127 | - * @param string $view View identifier to create a view for. |
|
128 | - * @param array $context Optional. The context in which to render the view. |
|
129 | - * @param string|null $type Type of view to create. |
|
130 | - * |
|
131 | - * @return string Rendered HTML content. |
|
132 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
133 | - * @throws FailedToInstantiateView If the View could not be instantiated. |
|
134 | - */ |
|
135 | - public function section(string $view, array $context = null, $type = null): string |
|
136 | - { |
|
137 | - if (null === $context) { |
|
138 | - $context = $this->_context_; |
|
139 | - } |
|
140 | - |
|
141 | - $this->initializeViewBuilder(); |
|
142 | - $viewObject = $this->_builder_->create($view, $type); |
|
143 | - |
|
144 | - return $viewObject->render($context); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the entire array of contextual data. |
|
149 | - * |
|
150 | - * @since 0.4.0 |
|
151 | - * |
|
152 | - * @return array Array of contextual data. |
|
153 | - */ |
|
154 | - public function getContext(): array |
|
155 | - { |
|
156 | - return $this->_context_; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Associate a view builder with this view. |
|
161 | - * |
|
162 | - * @since 0.2.0 |
|
163 | - * |
|
164 | - * @param ViewBuilder $builder |
|
165 | - * |
|
166 | - * @return View |
|
167 | - */ |
|
168 | - public function setBuilder(ViewBuilder $builder): View |
|
169 | - { |
|
170 | - $this->_builder_ = $builder; |
|
171 | - |
|
172 | - return $this; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Initialize the view builder associated with the view. |
|
177 | - * |
|
178 | - * @since 0.2.0 |
|
179 | - * |
|
180 | - * @throws FailedToProcessConfigException If the Config could not be processed. |
|
181 | - */ |
|
182 | - protected function initializeViewBuilder() |
|
183 | - { |
|
184 | - if (null === $this->_builder_) { |
|
185 | - $this->_builder_ = Views::getViewBuilder(); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Assimilate the context to make it available as properties. |
|
191 | - * |
|
192 | - * @since 0.2.0 |
|
193 | - * |
|
194 | - * @param array $context Context to assimilate. |
|
195 | - */ |
|
196 | - protected function assimilateContext(array $context = []) |
|
197 | - { |
|
198 | - $this->_context_ = $context; |
|
199 | - foreach ($context as $key => $value) { |
|
200 | - $this->$key = $value; |
|
201 | - } |
|
202 | - } |
|
33 | + /** |
|
34 | + * URI of the view. |
|
35 | + * |
|
36 | + * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
37 | + * |
|
38 | + * @since 0.1.0 |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_uri_; |
|
43 | + |
|
44 | + /** |
|
45 | + * Engine to use for the view. |
|
46 | + * |
|
47 | + * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
48 | + * |
|
49 | + * @since 0.1.0 |
|
50 | + * |
|
51 | + * @var Engine |
|
52 | + */ |
|
53 | + protected $_engine_; |
|
54 | + |
|
55 | + /** |
|
56 | + * ViewBuilder instance. |
|
57 | + * |
|
58 | + * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
59 | + * |
|
60 | + * @since 0.2.0 |
|
61 | + * |
|
62 | + * @var ViewBuilder |
|
63 | + */ |
|
64 | + protected $_builder_; |
|
65 | + |
|
66 | + /** |
|
67 | + * The context with which the view will be rendered. |
|
68 | + * |
|
69 | + * The underscores are used to prevent accidental use of these properties from within the rendering closure. |
|
70 | + * |
|
71 | + * @since 0.4.0 |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + protected $_context_ = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * Instantiate an AbstractView object. |
|
79 | + * |
|
80 | + * @since 0.1.0 |
|
81 | + * |
|
82 | + * @param string $uri URI for the view. |
|
83 | + * @param Engine $engine Engine to use for the view. |
|
84 | + */ |
|
85 | + public function __construct(string $uri, Engine $engine) |
|
86 | + { |
|
87 | + $this->_uri_ = $uri; |
|
88 | + $this->_engine_ = $engine; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Render the view. |
|
93 | + * |
|
94 | + * @since 0.1.0 |
|
95 | + * |
|
96 | + * @param array $context Optional. The context in which to render the view. |
|
97 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
98 | + * |
|
99 | + * @return string Rendered HTML. |
|
100 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
101 | + */ |
|
102 | + public function render(array $context = [], bool $echo = false): string |
|
103 | + { |
|
104 | + $this->initializeViewBuilder(); |
|
105 | + $this->assimilateContext($context); |
|
106 | + |
|
107 | + $closure = Closure::bind( |
|
108 | + $this->_engine_->getRenderCallback($this->_uri_, $context), |
|
109 | + $this, |
|
110 | + static::class |
|
111 | + ); |
|
112 | + |
|
113 | + $output = $closure(); |
|
114 | + |
|
115 | + if ($echo) { |
|
116 | + echo $output; |
|
117 | + } |
|
118 | + |
|
119 | + return $output; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Render a partial view (or section) for a given URI. |
|
124 | + * |
|
125 | + * @since 0.2.0 |
|
126 | + * |
|
127 | + * @param string $view View identifier to create a view for. |
|
128 | + * @param array $context Optional. The context in which to render the view. |
|
129 | + * @param string|null $type Type of view to create. |
|
130 | + * |
|
131 | + * @return string Rendered HTML content. |
|
132 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
133 | + * @throws FailedToInstantiateView If the View could not be instantiated. |
|
134 | + */ |
|
135 | + public function section(string $view, array $context = null, $type = null): string |
|
136 | + { |
|
137 | + if (null === $context) { |
|
138 | + $context = $this->_context_; |
|
139 | + } |
|
140 | + |
|
141 | + $this->initializeViewBuilder(); |
|
142 | + $viewObject = $this->_builder_->create($view, $type); |
|
143 | + |
|
144 | + return $viewObject->render($context); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the entire array of contextual data. |
|
149 | + * |
|
150 | + * @since 0.4.0 |
|
151 | + * |
|
152 | + * @return array Array of contextual data. |
|
153 | + */ |
|
154 | + public function getContext(): array |
|
155 | + { |
|
156 | + return $this->_context_; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Associate a view builder with this view. |
|
161 | + * |
|
162 | + * @since 0.2.0 |
|
163 | + * |
|
164 | + * @param ViewBuilder $builder |
|
165 | + * |
|
166 | + * @return View |
|
167 | + */ |
|
168 | + public function setBuilder(ViewBuilder $builder): View |
|
169 | + { |
|
170 | + $this->_builder_ = $builder; |
|
171 | + |
|
172 | + return $this; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Initialize the view builder associated with the view. |
|
177 | + * |
|
178 | + * @since 0.2.0 |
|
179 | + * |
|
180 | + * @throws FailedToProcessConfigException If the Config could not be processed. |
|
181 | + */ |
|
182 | + protected function initializeViewBuilder() |
|
183 | + { |
|
184 | + if (null === $this->_builder_) { |
|
185 | + $this->_builder_ = Views::getViewBuilder(); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Assimilate the context to make it available as properties. |
|
191 | + * |
|
192 | + * @since 0.2.0 |
|
193 | + * |
|
194 | + * @param array $context Context to assimilate. |
|
195 | + */ |
|
196 | + protected function assimilateContext(array $context = []) |
|
197 | + { |
|
198 | + $this->_context_ = $context; |
|
199 | + foreach ($context as $key => $value) { |
|
200 | + $this->$key = $value; |
|
201 | + } |
|
202 | + } |
|
203 | 203 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -26,74 +26,74 @@ |
||
26 | 26 | class NullView implements View, NullFindable |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Check whether the Findable can handle an individual criterion. |
|
31 | - * |
|
32 | - * @since 0.1.0 |
|
33 | - * |
|
34 | - * @param mixed $criterion Criterion to check. |
|
35 | - * |
|
36 | - * @return bool Whether the Findable can handle the criterion. |
|
37 | - */ |
|
38 | - public function canHandle($criterion): bool |
|
39 | - { |
|
40 | - return true; |
|
41 | - } |
|
29 | + /** |
|
30 | + * Check whether the Findable can handle an individual criterion. |
|
31 | + * |
|
32 | + * @since 0.1.0 |
|
33 | + * |
|
34 | + * @param mixed $criterion Criterion to check. |
|
35 | + * |
|
36 | + * @return bool Whether the Findable can handle the criterion. |
|
37 | + */ |
|
38 | + public function canHandle($criterion): bool |
|
39 | + { |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Render the view. |
|
45 | - * |
|
46 | - * @since 0.1.0 |
|
47 | - * |
|
48 | - * @param array $context Optional. The context in which to render the view. |
|
49 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
50 | - * |
|
51 | - * @return string Rendered HTML. |
|
52 | - */ |
|
53 | - public function render(array $context = [], bool $echo = false): string |
|
54 | - { |
|
55 | - return ''; |
|
56 | - } |
|
43 | + /** |
|
44 | + * Render the view. |
|
45 | + * |
|
46 | + * @since 0.1.0 |
|
47 | + * |
|
48 | + * @param array $context Optional. The context in which to render the view. |
|
49 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. |
|
50 | + * |
|
51 | + * @return string Rendered HTML. |
|
52 | + */ |
|
53 | + public function render(array $context = [], bool $echo = false): string |
|
54 | + { |
|
55 | + return ''; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Render a partial view (or section) for a given URI. |
|
60 | - * |
|
61 | - * @since 0.2.0 |
|
62 | - * |
|
63 | - * @param string $view View identifier to create a view for. |
|
64 | - * @param array $context Optional. The context in which to render the view. |
|
65 | - * @param string|null $type Type of view to create. |
|
66 | - * |
|
67 | - * @return string Rendered HTML content. |
|
68 | - */ |
|
69 | - public function section(string $view, array $context = [], $type = null): string |
|
70 | - { |
|
71 | - return ''; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Render a partial view (or section) for a given URI. |
|
60 | + * |
|
61 | + * @since 0.2.0 |
|
62 | + * |
|
63 | + * @param string $view View identifier to create a view for. |
|
64 | + * @param array $context Optional. The context in which to render the view. |
|
65 | + * @param string|null $type Type of view to create. |
|
66 | + * |
|
67 | + * @return string Rendered HTML content. |
|
68 | + */ |
|
69 | + public function section(string $view, array $context = [], $type = null): string |
|
70 | + { |
|
71 | + return ''; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Get the entire array of contextual data. |
|
76 | - * |
|
77 | - * @since 0.4.0 |
|
78 | - * |
|
79 | - * @return array Array of contextual data. |
|
80 | - */ |
|
81 | - public function getContext(): array |
|
82 | - { |
|
83 | - return []; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Get the entire array of contextual data. |
|
76 | + * |
|
77 | + * @since 0.4.0 |
|
78 | + * |
|
79 | + * @return array Array of contextual data. |
|
80 | + */ |
|
81 | + public function getContext(): array |
|
82 | + { |
|
83 | + return []; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Associate a view builder with this view. |
|
88 | - * |
|
89 | - * @since 0.2.0 |
|
90 | - * |
|
91 | - * @param ViewBuilder $builder |
|
92 | - * |
|
93 | - * @return View |
|
94 | - */ |
|
95 | - public function setBuilder(ViewBuilder $builder): View |
|
96 | - { |
|
97 | - return $this; |
|
98 | - } |
|
86 | + /** |
|
87 | + * Associate a view builder with this view. |
|
88 | + * |
|
89 | + * @since 0.2.0 |
|
90 | + * |
|
91 | + * @param ViewBuilder $builder |
|
92 | + * |
|
93 | + * @return View |
|
94 | + */ |
|
95 | + public function setBuilder(ViewBuilder $builder): View |
|
96 | + { |
|
97 | + return $this; |
|
98 | + } |
|
99 | 99 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -25,40 +25,40 @@ |
||
25 | 25 | class BaseEngineFinder extends AbstractFinder implements EngineFinder |
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 | - * |
|
35 | - * @return Engine Result of the search. |
|
36 | - * @throws FailedToInstantiateFindable If the Findable could not be instantiated. |
|
37 | - */ |
|
38 | - public function find(array $criteria): Engine |
|
39 | - { |
|
40 | - $this->initializeFindables(); |
|
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 | + * |
|
35 | + * @return Engine Result of the search. |
|
36 | + * @throws FailedToInstantiateFindable If the Findable could not be instantiated. |
|
37 | + */ |
|
38 | + public function find(array $criteria): Engine |
|
39 | + { |
|
40 | + $this->initializeFindables(); |
|
41 | 41 | |
42 | - foreach ($criteria as $entry) { |
|
43 | - foreach ($this->findables as $engine) { |
|
44 | - if ($engine->canHandle($entry)) { |
|
45 | - return $engine; |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
42 | + foreach ($criteria as $entry) { |
|
43 | + foreach ($this->findables as $engine) { |
|
44 | + if ($engine->canHandle($entry)) { |
|
45 | + return $engine; |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - return $this->getNullObject(); |
|
51 | - } |
|
50 | + return $this->getNullObject(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the config key for the Findables definitions. |
|
55 | - * |
|
56 | - * @since 0.1.0 |
|
57 | - * |
|
58 | - * @return string Config key use to define the Findables. |
|
59 | - */ |
|
60 | - protected function getFindablesConfigKey(): string |
|
61 | - { |
|
62 | - return 'Engines'; |
|
63 | - } |
|
53 | + /** |
|
54 | + * Get the config key for the Findables definitions. |
|
55 | + * |
|
56 | + * @since 0.1.0 |
|
57 | + * |
|
58 | + * @return string Config key use to define the Findables. |
|
59 | + */ |
|
60 | + protected function getFindablesConfigKey(): string |
|
61 | + { |
|
62 | + return 'Engines'; |
|
63 | + } |
|
64 | 64 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -24,15 +24,15 @@ |
||
24 | 24 | interface Engine extends Findable |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Get the rendering callback for a given URI. |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param string $uri URI to render. |
|
33 | - * @param array $context Context in which to render. |
|
34 | - * |
|
35 | - * @return callable Render callback. |
|
36 | - */ |
|
37 | - public function getRenderCallback(string $uri, array $context = []): callable; |
|
27 | + /** |
|
28 | + * Get the rendering callback for a given URI. |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param string $uri URI to render. |
|
33 | + * @param array $context Context in which to render. |
|
34 | + * |
|
35 | + * @return callable Render callback. |
|
36 | + */ |
|
37 | + public function getRenderCallback(string $uri, array $context = []): callable; |
|
38 | 38 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -23,8 +23,8 @@ |
||
23 | 23 | */ |
24 | 24 | interface EngineFinder extends Finder |
25 | 25 | { |
26 | - // Constants to be used for the Config file sections. |
|
27 | - const CLASS_NAME_KEY = 'ClassName'; |
|
28 | - const ENGINES_KEY = 'Engines'; |
|
29 | - const NULL_OBJECT = 'NullObject'; |
|
26 | + // Constants to be used for the Config file sections. |
|
27 | + const CLASS_NAME_KEY = 'ClassName'; |
|
28 | + const ENGINES_KEY = 'Engines'; |
|
29 | + const NULL_OBJECT = 'NullObject'; |
|
30 | 30 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |
@@ -1,4 +1,4 @@ |
||
1 | -<?php declare(strict_types=1); |
|
1 | +<?php declare(strict_types = 1); |
|
2 | 2 | /** |
3 | 3 | * Bright Nucleus View Component. |
4 | 4 | * |