-
-
Notifications
You must be signed in to change notification settings - Fork 324
Extending other object definitions (e.g. parent classes) #279
Copy link
Copy link
Open
Labels
Description
Hi. Is there a way in PHP-DI to define dependencies for an abstract object? Most logical way, to define parameters for a constructor for abstract object which would later be resolved for child object, does not work:
abstract class AbstractObject {
protected $a;
public function __construct($a) { $this->a = $a; }
}
class ConcreteObject extends AbstractObject {}
$builder = new DI\ContainerBuilder;
$builder->useAutowiring(true);
$builder->addDefinitions([
'AbstractObject' => DI\object()->constructorParameter('a', 'abc')
]);
$container = $builder->build();
$container->make('ConcreteObject');This code result in
PHP Fatal error: Uncaught exception 'DI\Definition\Exception\DefinitionException'
with message 'Entry ConcreteObject cannot be resolved: The parameter 'a' of
AbstractObject::__construct has no value defined or guessable
Full definition:
Object (
class = ConcreteObject
scope = singleton
lazy = false
__construct(
$a = #UNDEFINED#
)
)'
Am I missing something from the documentation or PHP-DI is unable at this point to realize this scenario?
Reactions are currently unavailable