I’d like to have the following class configuration.
class Parent
{
protected ParentMapperInterface $mapper;
public function __construct(ParentMapperInterface $mapper)
{
$this->mapper = $mapper;
}
// other methods that I would like to be available to all children
}
class Child1 extends Parent
{
protected Child1MapperInterface $mapper
public function __construct(Child1MapperInterface $childMapper)
{
$this->mapper = $childMapper;
}
}
class Child2 extends Parent
{
protected Child2MapperInterface $mapper
public function __construct(Child2MapperInterface $childMapper)
{
$this->mapper = $childMapper;
}
}
// other children
Child1
extends Parent
and has its Child1Mapper
under $mapper
property. The same is for Child2
.
Child1Mapper
, Child2Mapper
extend ParentMapper
. I made such class configuration because Child1
, Child2
, etc. share
same methods as Parent
, and Child1Mapper
, Child2Mapper
, etc. share some methods of ParentMapper
.
The problem is that with this configuration I get a PHP error that signatures of __construct
methods of Parent
and Child
should be the same.
Any idea how to get what I want?