I'm working on my own ORM with Entity and EntityRepository classes
In any ORM i explored injecting any services into Entities is realy bad idea. But there's a question: is it good idea to inject service into Repository?
There's abstract example:
//$user is object of Entity class in ORM
//we need to get actual valid entities here
$relatedEntities = $user->getRelatedEntities();
//where getRelatedEntities() calls method of RelatedEntityRepository
RelatedEntityRepository {
private $injectedService;
public function getByUserId($userId){
if(!$this->injectedService->hasValidUserData($userId)){
$this->injectedService->doSomething($userId);
}
return $this->getFromDbByUserId($userId)
}
private function getFromDbByUserId($userId){
//returns data from DB
}
}