My goal is to use DI in ancestor objects using setters so I have a common DI for ancestor objects. e.g. an abstract model class my other models inherit from, preconfigured with an entity manager etc.
So far, after configuring the ancestor and creating it with DI successfully, changing it to an abstract class, then instantiating an ancestor of that class the DI for the abstract (whether set to abstract or not) doesn't run.
namespace Stuki;
use Doctrine\ORM\EntityManager;
# abstract
class Model {
protected $em;
public function setEm(EntityManager $em) {
$this->em = $em;
}
}
The DI for this class
'di' => array(
'instance' => array(
'Stuki\Model' => array(
'parameters' => array(
'em' => 'doctrine_em'
)
),
The above class and DI will work. But I want that to run on ancestor objects so
namespace Stuki\Model;
use Stuki\Model as StukiModel;
class Authentication extends StukiModel {
public function getIdentity() {
return 'ħ'; #die('get identity');
}
}
$auth = $e->getTarget()->getLocator()->get('Stuki\Model\Authentication');
The last line, $auth = , doesn't run the DI.
How can I setup DI for ancestor objects, without using introspection?