Skip to content

Commit

Permalink
Add an example of working delegation to illustrate how delegation _ca…
Browse files Browse the repository at this point in the history
…n_ occur for aliased services

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel authored and boesing committed Jul 24, 2021
1 parent 9144f9b commit a3dbffd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/book/delegators.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,23 @@ $serviceManager = new Laminas\ServiceManager\ServiceManager([
],
]);
```

In order for delegation to occur, the above configuration would need to be modified to target the resolved service name:

```php
$serviceManager = new Laminas\ServiceManager\ServiceManager([
'factories' => [
Buzzer::class => Laminas\ServiceManager\Factory\InvokableFactory::class,
],
'aliases' => [
BuzzerInterface::class => Buzzer::class,
],
'delegators' => [
Buzzer::class => [
BuzzerDelegatorFactory::class, // will now execute as expected
],
],
]);
```

Retrieving the `Buzzer` using its resolved name "`Buzzer::class`" or its alias "`BuzzerInterface::class`" will now both yield delegated instances.

0 comments on commit a3dbffd

Please sign in to comment.