@@ -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,81 @@ 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
+ ## Invokables
81
163
82
164
* Invokables no longer exist,* at least, not identically to how they existed in
83
165
ZF2.
@@ -135,7 +217,7 @@ if needed).
135
217
> }
136
218
> ```
137
219
138
- ### Lazy Services
220
+ ## Lazy Services
139
221
140
222
In v2, if you wanted to create a lazy service, you needed to take the following
141
223
steps:
@@ -680,7 +762,6 @@ We may re-introduce it via a separate component in the future.
680
762
The following interfaces, traits, and classes were * removed* :
681
763
682
764
- ` Zend\ServiceManager\Config `
683
- - ` Zend\ServiceManager\ConfigInterface `
684
765
- ` Zend\ServiceManager\MutableCreationOptionsInterface ` ; this was previously
685
766
used by the ` AbstractPluginManager ` , and is no longer required as we ship a
686
767
separate ` PluginManagerInterface ` , and because the functionality is
@@ -697,8 +778,12 @@ too often abused under v2, and represent the antithesis of the purpose of the
697
778
Service Manager component; dependencies should be directly injected, and the
698
779
container should never be composed by objects.
699
780
700
- The following classes have changes:
781
+ The following classes and interfaces have changes:
701
782
702
783
- ` Zend\ServiceManager\Proxy\LazyServiceFactory ` is now marked ` final ` , and
703
784
implements ` Zend\ServiceManager\Proxy\DelegatorFactoryInterface ` . Its
704
785
dependencies and capabilities remain the same.
786
+ - ` Zend\ServiceManager\ConfigInterface ` now is expected to * return* a
787
+ ` ServiceManager ` instance. This is because instances cannot be configured
788
+ in-situ; implementers will now need to call ` withConfig() ` and return the
789
+ instance returned by that method.
0 commit comments