Extend: definition
DI\add()
// Declare an array
return [
'array' => [
get(Entry::class),
],
];
// Modify an array
return [
'array' => add([
get(NewEntry::class),
]),
];
Extend: entry
DI\string
return [
'path.tmp' => '/tmp',
'log.file' => string('{path.tmp}/app.log'),
];
Extend: entry
DI\factory()
DI\decorate()
return [
// Decorate the same instance
ProductRepository::class => decorate(function($previous) {
return new CachedProductRepository($previous);
}),
];
Decorating another instance is just a normal factory getting a dependency from the container.
This will not be implemented, but left for documentation
Extend: definition
DI\object()
DI\extend()
return [
Foo::class => object(Bar::class)
->constructor(...),
];
return [
// Replace (BC break with PHP-DI 4)
Foo::class => object(Bim::class)
->constructor(...),
// Extend the previous definition
Foo::class => extend()
->constructorParameter(...),
// Extend another definition
Test::class => extend(Foo::class)
->constructorParameter(...),
];