6
6
* New BSD License
7
7
*/
8
8
declare (strict_types=1 );
9
+
9
10
namespace Zend \ConfigAggregatorModuleManager ;
10
11
11
12
use InvalidArgumentException ;
12
13
use Traversable ;
13
14
use Zend \Config \Config ;
14
15
use Zend \ModuleManager \Feature \ConfigProviderInterface ;
15
- use Zend \ModuleManager \Feature \ControllerProviderInterface ;
16
+ use Zend \ModuleManager \Feature \FilterProviderInterface ;
17
+ use Zend \ModuleManager \Feature \FormElementProviderInterface ;
18
+ use Zend \ModuleManager \Feature \HydratorProviderInterface ;
19
+ use Zend \ModuleManager \Feature \InputFilterProviderInterface ;
20
+ use Zend \ModuleManager \Feature \RouteProviderInterface ;
21
+ use Zend \ModuleManager \Feature \SerializerProviderInterface ;
16
22
use Zend \ModuleManager \Feature \ServiceProviderInterface ;
23
+ use Zend \ModuleManager \Feature \ValidatorProviderInterface ;
17
24
18
25
/**
19
26
* Provide a configuration by using zend-modulemanager Module files.
@@ -46,27 +53,24 @@ public function __construct($module)
46
53
47
54
public function __invoke (): array
48
55
{
49
- return array_replace_recursive ($ this ->getModuleConfig (), [
56
+ return array_filter ( array_replace_recursive ($ this ->getModuleConfig (), [
50
57
$ this ->getDependenciesIdentifier () => $ this ->getModuleDependencies (),
51
- ]);
52
- }
53
-
54
- private function getModuleDependencies (): array
55
- {
56
- $ module = $ this ->module ;
57
- if (! $ module instanceof ServiceProviderInterface) {
58
- return $ this ->dependencies ;
59
- }
60
-
61
- return array_replace_recursive ($ this ->dependencies , $ this ->convert ($ module ->getServiceConfig ()));
58
+ 'route_manager ' => $ this ->getRouteConfig (),
59
+ 'form_elements ' => $ this ->getFormElementConfig (),
60
+ 'filters ' => $ this ->getFilterConfig (),
61
+ 'validators ' => $ this ->getValidatorConfig (),
62
+ 'hydrators ' => $ this ->getHydratorConfig (),
63
+ 'input_filters ' => $ this ->getInputFilterConfig (),
64
+ 'serializers ' => $ this ->getSerializerConfig (),
65
+ ]));
62
66
}
63
67
64
68
private function getModuleConfig (): array
65
69
{
66
70
$ module = $ this ->module ;
67
71
68
- if (! $ module instanceof ConfigProviderInterface
69
- && ! is_callable ([$ module , 'getConfig ' ])
72
+ if (!$ module instanceof ConfigProviderInterface
73
+ && !is_callable ([$ module , 'getConfig ' ])
70
74
) {
71
75
return [];
72
76
}
@@ -96,7 +100,7 @@ private function convert($config): array
96
100
$ config = iterator_to_array ($ config );
97
101
}
98
102
99
- if (! is_array ($ config )) {
103
+ if (!is_array ($ config )) {
100
104
throw new InvalidArgumentException (sprintf (
101
105
'Config being merged must be an array, '
102
106
. 'implement the Traversable interface, or be an '
@@ -117,4 +121,77 @@ public function setDependenciesIdentifier(string $dependenciesIdentifier): void
117
121
{
118
122
$ this ->dependenciesIdentifier = (string ) $ dependenciesIdentifier ;
119
123
}
124
+
125
+ private function getModuleDependencies (): array
126
+ {
127
+ $ module = $ this ->module ;
128
+ if (!$ module instanceof ServiceProviderInterface) {
129
+ return $ this ->dependencies ;
130
+ }
131
+
132
+ return array_replace_recursive ($ this ->dependencies , $ this ->convert ($ module ->getServiceConfig ()));
133
+ }
134
+
135
+ public function getRouteConfig (): array
136
+ {
137
+ if (!$ this ->module instanceof RouteProviderInterface) {
138
+ return [];
139
+ }
140
+
141
+ return $ this ->convert ($ this ->module ->getRouteConfig ());
142
+ }
143
+
144
+ public function getFormElementConfig (): array
145
+ {
146
+ if (!$ this ->module instanceof FormElementProviderInterface) {
147
+ return [];
148
+ }
149
+
150
+ return $ this ->convert ($ this ->module ->getFormElementConfig ());
151
+ }
152
+
153
+ public function getFilterConfig (): array
154
+ {
155
+ if (!$ this ->module instanceof FilterProviderInterface) {
156
+ return [];
157
+ }
158
+
159
+ return $ this ->convert ($ this ->module ->getFilterConfig ());
160
+ }
161
+
162
+ public function getValidatorConfig (): array
163
+ {
164
+ if (!$ this ->module instanceof ValidatorProviderInterface) {
165
+ return [];
166
+ }
167
+
168
+ return $ this ->convert ($ this ->module ->getValidatorConfig ());
169
+ }
170
+
171
+ public function getHydratorConfig (): array
172
+ {
173
+ if (!$ this ->module instanceof HydratorProviderInterface) {
174
+ return [];
175
+ }
176
+
177
+ return $ this ->convert ($ this ->module ->getHydratorConfig ());
178
+ }
179
+
180
+ public function getInputFilterConfig ()
181
+ {
182
+ if (!$ this ->module instanceof InputFilterProviderInterface) {
183
+ return [];
184
+ }
185
+
186
+ return $ this ->convert ($ this ->module ->getInputFilterConfig ());
187
+ }
188
+
189
+ public function getSerializerConfig (): array
190
+ {
191
+ if (!$ this ->module instanceof SerializerProviderInterface) {
192
+ return [];
193
+ }
194
+
195
+ return $ this ->convert ($ this ->module ->getSerializerConfig ());
196
+ }
120
197
}
0 commit comments