src/EventSubscriber/ProduitEventSubscriber.php line 47

Open in your IDE?
  1. <?php
  2.     namespace App\EventSubscriber;
  3.     /* 
  4.     bin/stripe listen --forward-to localhost:4242/cultureroute/public/stripe/webhook
  5.     */
  6.     use App\Event\ProduitEvent;
  7.     use App\Event\OrderEvent;
  8.     use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9.     use Psr\Log\LoggerInterface;
  10.     use App\Cacher\ShopProduitCacher;
  11.     use Doctrine\ORM\EntityManagerInterface;
  12.     class ProduitEventSubscriber implements EventSubscriberInterface
  13.     {
  14.         private $entityManager;
  15.         private $logger;
  16.         private $cacher;
  17.         public function __construct(LoggerInterface $lifecycleLoggerEntityManagerInterface $entityManagerShopProduitCacher $cacher)
  18.         {
  19.             $this->logger $lifecycleLogger;
  20.             $this->entityManager $entityManager;
  21.             $this->cacher $cacher;
  22.         }
  23.         public static function getSubscribedEvents() : array
  24.         {
  25.             return [
  26.                 ProduitEvent::CREATED => 'onProductCreated',
  27.                 ProduitEvent::UPDATED => 'onProductUpdated',
  28.                 ProduitEvent::DELETED => 'onProductDeleted',
  29.             ];
  30.         }
  31.        
  32.         public function onProductCreated(ProduitEvent $event)
  33.         {
  34.             $Produit $event->getProduit();
  35.             // Log the event
  36.             $this->logger->info(ProduitEvent::CREATED, [
  37.                 'produit'=>$Produit->getIntitule(),
  38.             ]);
  39.             $this->cacher->delete($Produit);
  40.         }
  41.         public function onProductUpdated(ProduitEvent $event)
  42.         {
  43.             $Produit $event->getProduit();
  44.             // Log the event
  45.             $this->logger->info(ProduitEvent::UPDATED, [
  46.                 'produit'=>$Produit->getIntitule(),
  47.             ]);
  48.             $this->cacher->delete($Produit);
  49.         }
  50.         public function onProductDeleted(ProduitEvent $event)
  51.         {
  52.             $Produit $event->getProduit();
  53.             // Log the event
  54.             $this->logger->info(ProduitEvent::DELETED, [
  55.                 'produit'=>$Produit->getIntitule(),
  56.             ]);
  57.             $this->cacher->delete($Produit);
  58.         }
  59.     }