Vote count:
0
I'm using PHP and the Doctrine ORM and here's the deal: I have a product table with an image field and I want an event to check if an image exists in my assets cloud storage (Amazon S3). If the file exists then all is well but if it does not I would like to return the file-path of a placeholder image. Now the method that perform the check for the existence of the image resides in my S3Service class.
Is there a way for me to tie an event to the entity such that every time I call something like:
$product = $this->em->getRepository('Entities\Product')
->findBy(['id' => $productId]);
echo $product->getImagePath();
I would be able to get the default image if the file is non existent. Now I know you shouldn't inject services into entities but it would be much cleaner for the rest of my code if I can abstract this part with my entity. That's why I'm looking at an event driven kind of solution. I have looked at the life cycle events of doctrine entities but I don't know if there's an event which executes as soon as the entity is retrieved.
Injecting services into Entities: check if an image file exists
Aucun commentaire:
Enregistrer un commentaire