<?php
namespace App\EventSubscriber;
/*
bin/stripe listen --forward-to localhost:4242/cultureroute/public/stripe/webhook
*/
use App\Event\ProduitEvent;
use App\Event\OrderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Psr\Log\LoggerInterface;
use App\Cacher\ShopProduitCacher;
use Doctrine\ORM\EntityManagerInterface;
class ProduitEventSubscriber implements EventSubscriberInterface
{
private $entityManager;
private $logger;
private $cacher;
public function __construct(LoggerInterface $lifecycleLogger, EntityManagerInterface $entityManager, ShopProduitCacher $cacher)
{
$this->logger = $lifecycleLogger;
$this->entityManager = $entityManager;
$this->cacher = $cacher;
}
public static function getSubscribedEvents() : array
{
return [
ProduitEvent::CREATED => 'onProductCreated',
ProduitEvent::UPDATED => 'onProductUpdated',
ProduitEvent::DELETED => 'onProductDeleted',
];
}
public function onProductCreated(ProduitEvent $event)
{
$Produit = $event->getProduit();
// Log the event
$this->logger->info(ProduitEvent::CREATED, [
'produit'=>$Produit->getIntitule(),
]);
$this->cacher->delete($Produit);
}
public function onProductUpdated(ProduitEvent $event)
{
$Produit = $event->getProduit();
// Log the event
$this->logger->info(ProduitEvent::UPDATED, [
'produit'=>$Produit->getIntitule(),
]);
$this->cacher->delete($Produit);
}
public function onProductDeleted(ProduitEvent $event)
{
$Produit = $event->getProduit();
// Log the event
$this->logger->info(ProduitEvent::DELETED, [
'produit'=>$Produit->getIntitule(),
]);
$this->cacher->delete($Produit);
}
}