@@ -25,6 +25,14 @@ registered.
25
25
26
26
## Configuration
27
27
28
+ A number of changes have been made to configuration of service and plugin
29
+ managers:
30
+
31
+ - Minor changes in configuration arrays may impact your usage.
32
+ - ` ConfigInterface ` implementations and consumers will need updating.
33
+
34
+ ### Configuration arrays
35
+
28
36
Configuration for v2 consisted of the following:
29
37
30
38
``` php
@@ -77,7 +85,89 @@ In v3, the configuration remains the same, with the following additions:
77
85
The main change is the addition of integrated lazy service configuration is now
78
86
integrated.
79
87
80
- ### Invokables
88
+ ### ConfigInterface
89
+
90
+ The ` ServiceManager ` is now immutable, meaning that you cannot configure it
91
+ after-the-fact. If your ` ConfigInterface ` implementation called on the various
92
+ methods for injecting new services, such as:
93
+
94
+ - ` setService() `
95
+ - ` setInvokableClass() `
96
+ - ` setFactory() `
97
+ - ` addAbstractFactory() `
98
+ - ` addInitializer() `
99
+ - ` addDelegator() `
100
+
101
+ then you will need to alter the logic to instead aggregate a full configuration
102
+ specification. This can then be passed to the ` ServiceManager ` instance's
103
+ ` withConfig() ` method, which does the following:
104
+
105
+ - Creates a clone of the manager.
106
+ - Merges the incoming configuration with the current configuration within the
107
+ clone.
108
+ - Returns the clone.
109
+
110
+ As such, your implementation should return the result of
111
+ ` $serviceManager->withConfig() ` .
112
+
113
+ As an example, consider this ` HelperConfig ` implementation from zend-i18n
114
+ v2:
115
+
116
+ ``` php
117
+ class HelperConfig implements ConfigInterface
118
+ {
119
+ protected $invokables = [
120
+ 'currencyformat' => 'Zend\I18n\View\Helper\CurrencyFormat',
121
+ 'dateformat' => 'Zend\I18n\View\Helper\DateFormat',
122
+ 'numberformat' => 'Zend\I18n\View\Helper\NumberFormat',
123
+ 'plural' => 'Zend\I18n\View\Helper\Plural',
124
+ 'translate' => 'Zend\I18n\View\Helper\Translate',
125
+ 'translateplural' => 'Zend\I18n\View\Helper\TranslatePlural',
126
+ ];
127
+
128
+ public function configureServiceManager(ServiceManager $serviceManager)
129
+ {
130
+ foreach ($this->invokables as $name => $service) {
131
+ $serviceManager->setInvokableClass($name, $service);
132
+ }
133
+ }
134
+ }
135
+ ```
136
+
137
+ In version 3, this will become:
138
+
139
+ ``` php
140
+ use Interop\Container\ContainerInterface;
141
+
142
+ class HelperConfig implements ConfigInterface
143
+ {
144
+ protected $invokables = [
145
+ 'currencyformat' => 'Zend\I18n\View\Helper\CurrencyFormat',
146
+ 'dateformat' => 'Zend\I18n\View\Helper\DateFormat',
147
+ 'numberformat' => 'Zend\I18n\View\Helper\NumberFormat',
148
+ 'plural' => 'Zend\I18n\View\Helper\Plural',
149
+ 'translate' => 'Zend\I18n\View\Helper\Translate',
150
+ 'translateplural' => 'Zend\I18n\View\Helper\TranslatePlural',
151
+ ];
152
+
153
+ public function configureServiceManager(ServiceManager $serviceManager)
154
+ {
155
+ return $serviceManager->withConfig([
156
+ 'invokables' => $this->invokables,
157
+ ]);
158
+ }
159
+ }
160
+ ```
161
+
162
+ ### Config class
163
+
164
+ ` Zend\ServiceManager\Config ` has been updated to follow the changes to the
165
+ ` ConfigInterface ` and ` ServiceManager ` . This essentially means that it removes
166
+ the various getter methods, and that the ` configureServiceManager() ` method
167
+ instead aggregates the relevant configuration from the configuration passed to
168
+ the constructor to pass to ` ServiceManager::withConfig() ` .
169
+
170
+ ## Invokables
81
171
82
172
* Invokables no longer exist,* at least, not identically to how they existed in
83
173
ZF2.
@@ -135,7 +225,7 @@ if needed).
135
225
> }
136
226
> ```
137
227
138
- ### Lazy Services
228
+ ## Lazy Services
139
229
140
230
In v2, if you wanted to create a lazy service, you needed to take the following
141
231
steps:
@@ -679,8 +769,6 @@ We may re-introduce it via a separate component in the future.
679
769
680
770
The following interfaces, traits, and classes were * removed* :
681
771
682
- - ` Zend\ServiceManager\Config `
683
- - ` Zend\ServiceManager\ConfigInterface `
684
772
- ` Zend\ServiceManager\MutableCreationOptionsInterface ` ; this was previously
685
773
used by the ` AbstractPluginManager ` , and is no longer required as we ship a
686
774
separate ` PluginManagerInterface ` , and because the functionality is
@@ -697,8 +785,15 @@ too often abused under v2, and represent the antithesis of the purpose of the
697
785
Service Manager component; dependencies should be directly injected, and the
698
786
container should never be composed by objects.
699
787
700
- The following classes have changes:
788
+ The following classes and interfaces have changes:
701
789
702
790
- ` Zend\ServiceManager\Proxy\LazyServiceFactory ` is now marked ` final ` , and
703
791
implements ` Zend\ServiceManager\Proxy\DelegatorFactoryInterface ` . Its
704
792
dependencies and capabilities remain the same.
793
+ - ` Zend\ServiceManager\ConfigInterface ` now is expected to * return* a
794
+ ` ServiceManager ` instance. This is because instances cannot be configured
795
+ in-situ; implementers will now need to call ` withConfig() ` and return the
796
+ instance returned by that method.
797
+ - ` Zend\ServiceManager\Config ` was updated to follow the changes to
798
+ ` ConfigInterface ` and ` ServiceManager ` , and now returns a new
799
+ ` ServiceManager ` instance from ` configureServiceManager() ` .
0 commit comments