@@ -57,31 +57,10 @@ Configuration for v2 consisted of the following:
57
57
]
58
58
```
59
59
60
- In v3, the configuration remains roughly the same, with the following changes :
60
+ In v3, the configuration remains the same, with the following additions :
61
61
62
62
``` php
63
63
[
64
- 'services' => [
65
- // service name => instance pairs
66
- ],
67
- 'aliases' => [
68
- // alias => service name pairs
69
- ],
70
- 'factories' => [
71
- // service name => factory pairs
72
- ],
73
- 'abstract_factories' => [
74
- // abstract factories
75
- ],
76
- 'initializers' => [
77
- // initializers
78
- ],
79
- 'delegators' => [
80
- // service name => [ delegator factories ]
81
- ],
82
- 'shared' => [
83
- // service name => boolean
84
- ],
85
64
'lazy_services' => [
86
65
// The class_map is required if using lazy services:
87
66
'class_map' => [
@@ -92,69 +71,29 @@ In v3, the configuration remains roughly the same, with the following changes:
92
71
'proxies_target_dir' => 'path in which to write generated proxy classes',
93
72
'write_proxy_files' => true, // boolean; false by default
94
73
],
95
- 'share_by_default' => boolean,
96
74
]
97
75
```
98
76
99
- The main changes are that invokables no longer exist, and that lazy service
100
- configuration is now integrated.
77
+ The main change is the addition of integrated lazy service configuration is now
78
+ integrated.
101
79
102
80
### Invokables
103
81
104
- * Invokables no longer exist.* As such, that key is no longer relevant. In each
105
- case, if the service name is also the name of the class, you can use the
106
- ` InvokableFactory ` and assign the service as a factory.
107
-
108
- As an example, if you previously had the following configuration:
109
-
110
- ``` php
111
- return [
112
- 'invokables' => [
113
- 'MyClass' => 'MyClass',
114
- ],
115
- ];
116
- ```
117
-
118
- You will now use the following:
119
-
120
- ``` php
121
- use Zend\ServiceManager\Factory\InvokableFactory;
122
-
123
- return [
124
- 'factories' => [
125
- 'MyClass' => InvokableFactory::class,
126
- ],
127
- ];
128
- ```
129
-
130
- What if you were using a service name that differed from the class name?
131
-
132
- ``` php
133
- return [
134
- 'invokables' => [
135
- 'MyClass' => 'AnotherClass',
136
- ],
137
- ];
138
- ```
139
-
140
- In this case, you will create two separate entries: an invokable factory for the
141
- actual class, and an alias to it:
82
+ * Invokables no longer exist,* at least, not identically to how they existed in
83
+ ZF2.
142
84
143
- ``` php
144
- use Zend\ServiceManager\Factory\InvokableFactory;
85
+ Internally, ` ServiceManager ` now does the following for ` invokables ` entries:
145
86
146
- return [
147
- 'aliases' => [
148
- 'MyClass' => 'AnotherClass',
149
- ],
150
- 'invokables' => [
151
- 'AnotherClass' => InvokableFactory::class,
152
- ],
153
- ];
154
- ```
87
+ - If the name and value match, it creates a ` factories ` entry mapping the
88
+ service name to ` Zend\ServiceManager\Factory\InvokableFactory ` .
89
+ - If the name and value * do not* match, it creates an ` aliases ` entry mapping the
90
+ service name to the class name, * and* a ` factories ` entry mapping the class
91
+ name to ` Zend\ServiceManager\Factory\InvokableFactory ` .
155
92
156
- Alternately, you can create a dedicated factory for ` MyClass ` that instantiates
157
- the correct class.
93
+ This means that you can use your existing ` invokables ` configuration from
94
+ version 2 in version 3. However, we recommend starting to update your
95
+ configuration to remove ` invokables ` entries in favor of factories (and aliases,
96
+ if needed).
158
97
159
98
### Lazy Services
160
99
0 commit comments