FilmCreationListener.php 833 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Service;
  3. use App\Entity\Commentaire;
  4. use Doctrine\Persistence\Event\LifecycleEventArgs;
  5. use App\Entity\Film;
  6. use Symfony\Component\Config\Definition\Exception\Exception;
  7. class FilmCreationListener
  8. {
  9. public function __construct(protected Mattermost $mattermostSender)
  10. {
  11. }
  12. public function postPersist(LifecycleEventArgs $args): void
  13. {
  14. $entity = $args->getObject();
  15. if (!$entity instanceof Film and !$entity instanceof Commentaire)
  16. {
  17. return;
  18. }
  19. try {
  20. if ($entity instanceof Film)
  21. $this->mattermostSender->sendNouveauFilm($entity);
  22. else
  23. $this->mattermostSender->sendNouveauCommentaire($entity->getUser(), $entity->getFilm());
  24. } catch (Exception $exception) {
  25. }
  26. }
  27. }