I'm trying to implement DDD in php. I have an entity called message that has related fromFieldId. I want to validate that this fromField exists in database when it is set on message, I do not want to burden caller with this validation as it happens in many places in my code. However from what I understand in DDD entity should not call repositories? How would I handle this in DDD?
I want something like this:
class MessageEntity{
public function setFromFieldId($fromFieldId){
if(!$this->fromFieldRepository->isExists($fromFieldId)){
// throw some exception
}
$this->fromFieldId = $fromFieldId;
}
}