@@ -311,6 +311,16 @@ return [
311
311
];
312
312
```
313
313
314
+ Additionally, assuming you have configured lazy services initially with the
315
+ proxy namespace, target directory, etc., you can map lazy services using the new
316
+ method ` mapLazyService($name, $class) ` :
317
+
318
+ ``` php
319
+ $container->mapLazyService('MyClass', 'MyClass');
320
+ // or, more simply:
321
+ $container->mapLazyService('MyClass');
322
+ ```
323
+
314
324
## ServiceLocatorInterface Changes
315
325
316
326
The ` ServiceLocatorInterface ` now extends the
@@ -332,70 +342,32 @@ service, and to allow using the provided `$options` when creating the instance.
332
342
` Zend\ServiceManager\ServiceManager ` remains the primary interface with which
333
343
developers will interact. It has the following changes in v3:
334
344
335
- - It is now immutable.
336
- - It accepts all configuration at instantiation.
337
- - It removes all methods that would alter state.
338
- - It adds a new method, ` withConfig() ` , for generating a new instance that
339
- merges the provided configuration with previous definitions.
345
+ - It adds a new method, ` configure() ` , which allows configuring all instance
346
+ generation capabilities (aliases, factories, abstract factories, etc.) at
347
+ once.
340
348
- Peering capabilities were removed.
341
349
- Exceptions are * always* thrown when service instance creation fails or
342
350
produces an error; you can no longer disable this.
343
- - Configuration no longer requires a ` Zend\ServiceManager\Config ` instance; that
344
- class has been removed .
351
+ - Configuration no longer requires a ` Zend\ServiceManager\Config ` instance.
352
+ ` Config ` can be used, but is no needed .
345
353
- It adds a new method, ` build() ` , for creating discrete service instances.
346
354
347
355
### Methods Removed
348
356
349
357
* The following methods are removed* in v3:
350
358
351
- - ` setAllowOverride() ` /` getAllowOverride() ` ; since instances are now immutable,
352
- these no longer had any meaning.
353
359
- ` setShareByDefault() ` /` shareByDefault() ` ; this can be passed during
354
- instantiation or via ` withConfig ()` .
360
+ instantiation or via ` configure ()` .
355
361
- ` setThrowExceptionInCreate() ` /` getThrowExceptionInCreate() ` ; exceptions are
356
362
* always* thrown when errors are encountered during service instance creation.
357
363
- ` setRetrieveFromPeeringManagerFirst() ` /` retrieveFromPeeringManagerFirst() ` ;
358
364
peering is no longer supported.
359
- - ` setInvokableClass() ` ; invokable classes are no longer supported separately,
360
- regardless.
361
- - ` setFactory() ` ; pass factories during instantiation or via ` withConfig() ` .
362
- - ` addAbstractFactory() ` ; provide abstract factories during instantiation or via
363
- ` withConfig() ` .
364
- - ` addDelegator() ` ; provide delegator factories during instantiation or via
365
- ` withConfig() ` .
366
- - ` addInitializer() ` ; pass initializers during instantiation or via
367
- ` withConfig() ` .
368
- - ` setService() ` ; provide concrete service instances during instantiation or via
369
- ` withConfig() ` .
370
- - ` setShared() ` /` isShared() ` ; provide per-service sharing status at
371
- instantiation or via ` withConfig() ` .
372
365
373
366
### Constructor
374
367
375
368
The constructor now accepts an array of service configuration, not a
376
369
` Zend\ServiceManager\Config ` instance.
377
370
378
- ### Immutability
379
-
380
- The Service Manager is now immutable. This allows us to perform aggressive
381
- caching, and prevents the need to check for state changes when new services are
382
- added.
383
-
384
- * Typically, you should pass all service configuration at instantiation.*
385
-
386
- If you need to change a Service Manager instance — for instance, to add more
387
- factories, delegators, etc. — the class provides a new method, ` withConfig() ` .
388
- This method will merge the configuration you provide with that found in the
389
- Service Manager instance in order to return a * new instance* :
390
-
391
- ``` php
392
- $updated = $container->withConfig([
393
- 'factories' => [
394
- 'MyClass' => InvokableFactory::class,
395
- ],
396
- ]);
397
- ```
398
-
399
371
### Use ` build() ` for discrete instances
400
372
401
373
The new method ` build() ` acts as a factory method for configured services, and
@@ -758,10 +730,8 @@ The following classes and interfaces have changes:
758
730
- ` Zend\ServiceManager\Proxy\LazyServiceFactory ` is now marked ` final ` , and
759
731
implements ` Zend\ServiceManager\Proxy\DelegatorFactoryInterface ` . Its
760
732
dependencies and capabilities remain the same.
761
- - ` Zend\ServiceManager\ConfigInterface ` now is expected to * return* a
762
- ` ServiceManager ` instance. This is because instances cannot be configured
763
- in-situ; implementers will now need to call ` withConfig() ` and return the
764
- instance returned by that method.
733
+ - ` Zend\ServiceManager\ConfigInterface ` now is expected to * return* the modified
734
+ ` ServiceManager ` instance.
765
735
- ` Zend\ServiceManager\Config ` was updated to follow the changes to
766
- ` ConfigInterface ` and ` ServiceManager ` , and now returns a new
736
+ ` ConfigInterface ` and ` ServiceManager ` , and now returns the updated
767
737
` ServiceManager ` instance from ` configureServiceManager() ` .
0 commit comments