Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 617342b

Browse files
committed
Updated migration guide
Details how invokables work internally.
1 parent eec98b5 commit 617342b

File tree

1 file changed

+15
-76
lines changed

1 file changed

+15
-76
lines changed

doc/book/migration.md

Lines changed: 15 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,10 @@ Configuration for v2 consisted of the following:
5757
]
5858
```
5959

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:
6161

6262
```php
6363
[
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-
],
8564
'lazy_services' => [
8665
// The class_map is required if using lazy services:
8766
'class_map' => [
@@ -92,69 +71,29 @@ In v3, the configuration remains roughly the same, with the following changes:
9271
'proxies_target_dir' => 'path in which to write generated proxy classes',
9372
'write_proxy_files' => true, // boolean; false by default
9473
],
95-
'share_by_default' => boolean,
9674
]
9775
```
9876

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.
10179

10280
### Invokables
10381

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.
14284

143-
```php
144-
use Zend\ServiceManager\Factory\InvokableFactory;
85+
Internally, `ServiceManager` now does the following for `invokables` entries:
14586

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`.
15592

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).
15897

15998
### Lazy Services
16099

0 commit comments

Comments
 (0)