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

Commit e00f5d0

Browse files
committed
Merge branch 'weierophinney-feature/abstract-factory-disambiguation' into develop
Closes #59
2 parents 875bc98 + e9500b5 commit e00f5d0

16 files changed

+1255
-124
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ All notable changes to this project will be documented in this file, in reverse
6666
Of course, you can still override the `validate` method if your logic is more
6767
complex.
6868

69+
To aid migration, `validate()` will check for a `validatePlugin()` method (which
70+
was required in v2), and proxy to it if found, after emitting an
71+
`E_USER_DEPRECATED` notice prompting you to rename the method.
72+
6973
- A new method, `configure()`, was added, allowing full configuration of the
7074
`ServiceManager` instance at once. Each of the various configuration methods —
7175
`setAlias()`, `setInvokableClass()`, etc. — now proxy to this method.
@@ -168,6 +172,14 @@ changes, outlined in this section.
168172
enforced through the interface, that allows you to easily map multiple service
169173
names to the same factory.
170174

175+
To provide forwards compatibility, the original interfaces have been retained,
176+
but extend the new interfaces (which are under new namespaces). You can implement
177+
the new methods in your existing v2 factories in order to make them forwards
178+
compatible with v3.
179+
180+
- The for `AbstractFactoryInterface` interface renames the method `canCreateServiceWithName()`
181+
to `canCreate()`, and merges the `$name` and `$requestedName` arguments.
182+
171183
- Plugin managers will now receive the parent service locator instead of itself
172184
in factories. In version 2.x, you needed to call the method
173185
`getServiceLocator()` to retrieve the parent (application) service locator.
@@ -209,13 +221,21 @@ changes, outlined in this section.
209221
In practice, this should reduce code, as dependencies often come from the main
210222
service locator, and not the plugin manager itself.
211223

224+
To assist in migration, the method `getServiceLocator()` was added to `ServiceManager`
225+
to ensure that existing factories continue to work; the method emits an `E_USER_DEPRECATED`
226+
message to signal developers to update their factories.
227+
212228
- `PluginManager` now enforces the need for the main service locator in its
213229
constructor. In v2.x, people often forgot to set the parent locator, which led
214230
to bugs in factories trying to fetch dependencies from the parent locator.
215231
Additionally, plugin managers now pull dependencies from the parent locator by
216232
default; if you need to pull a peer plugin, your factories will now need to
217233
pull the corresponding plugin manager first.
218234

235+
If you omit passing a service locator to the constructor, your plugin manager
236+
will continue to work, but will emit a deprecation notice indicatin you
237+
should update your initialization code.
238+
219239
- It's so fast now that your app will fly!
220240

221241
## 2.6.1 - TBD

doc/book/configuring-the-service-manager.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ implement `Zend\ServiceManager\Factory\AbstractFactoryInterface`:
170170

171171
class MyAbstractFactory implements AbstractFactoryInterface
172172
{
173-
public function canCreateServiceWithName(ContainerInterface $container, $requestedName)
173+
public function canCreate(ContainerInterface $container, $requestedName)
174174
{
175175
return in_array('Traversable', class_implements($requestedName), true);
176176
}
@@ -198,14 +198,14 @@ Here is what will happen:
198198
`A::class` service.
199199
2. Because none is found, it will process each abstract factory, in the order
200200
in which they were registered.
201-
3. It will call the `canCreateServiceWithName()` method, passing the service
202-
manager instance and the name of the requested object. The method can use
203-
any logic whatsoever to determine if it can create the service (such as
204-
checking its name, checking for a required dependency in the passed
205-
container, checking if a class implements a given interface, etc.).
206-
4. If `canCreateServiceWithName` returns `true`, it will call the `__invoke`
207-
method to create the object. Otherwise, it will continue iterating the
208-
abstract factories, until one matches, or the queue is exhausted.
201+
3. It will call the `canCreate()` method, passing the service manager instance and
202+
the name of the requested object. The method can use any logic whatsoever to
203+
determine if it can create the service (such as checking its name, checking
204+
for a required dependency in the passed container, checking if a class
205+
implements a given interface, etc.).
206+
4. If `canCreate()` returns `true`, it will call the `__invoke` method to
207+
create the object. Otherwise, it will continue iterating the abstract
208+
factories, until one matches, or the queue is exhausted.
209209

210210
### Best practices
211211

0 commit comments

Comments
 (0)