123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace WorkflowBundle\EventListener;
- use Doctrine\Common\EventSubscriber;
- use Doctrine\ORM\Event\LifecycleEventArgs;
- use WorkflowBundle\Utils\DoctrineEvents;
- use WorkflowBundle\Services\ProducerService;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- class DoctrineEventSubscriber implements EventSubscriber
- {
-
- /**
- * @var ProducerService
- */
- private $producerService;
-
-
- /**
- * @param ContainerInterface $serviceContainer
- */
- public function __construct(ProducerService $producerService)
- {
- /* @var $this->producerService ProducerService */
- $this->producerService = $producerService;
- }
- /**
- * @return array
- */
- public function getSubscribedEvents()
- {
- return array(
- DoctrineEvents::PRE_PERSIST,
- DoctrineEvents::POST_PERSIST,
- DoctrineEvents::PRE_UPDATE,
- DoctrineEvents::POST_UPDATE,
- DoctrineEvents::PRE_REMOVE,
- DoctrineEvents::POST_REMOVE,
- );
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function prePersist(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::PRE_PERSIST);
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function postPersist(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::POST_PERSIST);
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function preUpdate(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::PRE_UPDATE);
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function postUpdate(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::POST_UPDATE);
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function preRemove(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::PRE_REMOVE);
- }
- /**
- * @param LifecycleEventArgs $args
- */
- public function postRemove(LifecycleEventArgs $args)
- {
- $this->execute($args, DoctrineEvents::POST_REMOVE);
- }
- /**
- * @param LifecycleEventArgs $args
- * @param string $eventName
- */
- public function execute(LifecycleEventArgs $args, $eventName = DoctrineEvents::PRE_PERSIST)
- {
- $this->producerService->execute($args->getEntity(), $eventName);
- }
- }
|