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

Commit 9e11bbc

Browse files
committed
Updated CHANGELOG and docs to reflect recent changes
1 parent 765c29a commit 9e11bbc

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
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,8 +172,13 @@ 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+
171180
- The for `AbstractFactoryInterface` interface renames the method `canCreateServiceWithName()`
172-
to `has()`, and merges the `$name` and `$requestedName` arguments.
181+
to `canCreate()`, and merges the `$name` and `$requestedName` arguments.
173182

174183
- Plugin managers will now receive the parent service locator instead of itself
175184
in factories. In version 2.x, you needed to call the method
@@ -212,13 +221,21 @@ changes, outlined in this section.
212221
In practice, this should reduce code, as dependencies often come from the main
213222
service locator, and not the plugin manager itself.
214223

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+
215228
- `PluginManager` now enforces the need for the main service locator in its
216229
constructor. In v2.x, people often forgot to set the parent locator, which led
217230
to bugs in factories trying to fetch dependencies from the parent locator.
218231
Additionally, plugin managers now pull dependencies from the parent locator by
219232
default; if you need to pull a peer plugin, your factories will now need to
220233
pull the corresponding plugin manager first.
221234

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+
222239
- It's so fast now that your app will fly!
223240

224241
## 2.6.1 - TBD

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

Lines changed: 5 additions & 5 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 has(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 `has()` method, passing the service manager instance and
201+
3. It will call the `canCreate()` method, passing the service manager instance and
202202
the name of the requested object. The method can use any logic whatsoever to
203203
determine if it can create the service (such as checking its name, checking
204204
for a required dependency in the passed container, checking if a class
205205
implements a given interface, etc.).
206-
4. If `has` returns `true`, it will call the `__invoke` method to create the
207-
object. Otherwise, it will continue iterating the abstract factories, until
208-
one matches, or the queue is exhausted.
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)