php - Injecting services into Entities: check if an image file exists -
i'm using php , doctrine orm , here's deal: have product table image field , want event check if image exists in assets cloud storage (amazon s3). if file exists if not return file-path of placeholder image. method perform check existence of image resides in s3service class.
is there way me tie event entity such every time call like:
$product = $this->em->getrepository('entities\product') ->findby(['id' => $productid]); echo $product->getimagepath();
i able default image if file non existent (by calling method in s3service of course). know shouldn't inject services entities cleaner rest of code if can abstract part entity. that's why i'm looking @ event driven kind of solution. have looked @ life cycle events of doctrine entities don't know if there's event executes entity retrieved.
question is: event should looking @ or should looking @ solution altogether?
it's not practice injecting services entities (eg. in method parameters). imo should create service operates on images , in specific methods gets entity parameter. kris wallsmith said on symfonycon - models thin layers between application , persistent (db) layer. shouldn't contains lot of logic.
Comments
Post a Comment