FilmCreationListener.php 971 B

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