vendor/sylius/resource-bundle/src/Bundle/Controller/EventDispatcher.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ResourceBundle\Controller;
  12. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  13. use Sylius\Component\Resource\Model\ResourceInterface;
  14. use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
  15. final class EventDispatcher implements EventDispatcherInterface
  16. {
  17.     /** @var SymfonyEventDispatcherInterface */
  18.     private $eventDispatcher;
  19.     public function __construct(SymfonyEventDispatcherInterface $eventDispatcher)
  20.     {
  21.         $this->eventDispatcher $eventDispatcher;
  22.     }
  23.     /**
  24.      * {@inheritdoc}
  25.      */
  26.     public function dispatch(
  27.         string $eventName,
  28.         RequestConfiguration $requestConfiguration,
  29.         ResourceInterface $resource
  30.     ): ResourceControllerEvent {
  31.         $eventName $requestConfiguration->getEvent() ?: $eventName;
  32.         $metadata $requestConfiguration->getMetadata();
  33.         $event = new ResourceControllerEvent($resource);
  34.         $this->eventDispatcher->dispatch(sprintf('%s.%s.%s'$metadata->getApplicationName(), $metadata->getName(), $eventName), $event);
  35.         return $event;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function dispatchMultiple(
  41.         string $eventName,
  42.         RequestConfiguration $requestConfiguration,
  43.         $resources
  44.     ): ResourceControllerEvent {
  45.         $eventName $requestConfiguration->getEvent() ?: $eventName;
  46.         $metadata $requestConfiguration->getMetadata();
  47.         $event = new ResourceControllerEvent($resources);
  48.         $this->eventDispatcher->dispatch(sprintf('%s.%s.%s'$metadata->getApplicationName(), $metadata->getName(), $eventName), $event);
  49.         return $event;
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     public function dispatchPreEvent(
  55.         string $eventName,
  56.         RequestConfiguration $requestConfiguration,
  57.         ResourceInterface $resource
  58.     ): ResourceControllerEvent {
  59.         $eventName $requestConfiguration->getEvent() ?: $eventName;
  60.         $metadata $requestConfiguration->getMetadata();
  61.         $event = new ResourceControllerEvent($resource);
  62.         $this->eventDispatcher->dispatch(sprintf('%s.%s.pre_%s'$metadata->getApplicationName(), $metadata->getName(), $eventName), $event);
  63.         return $event;
  64.     }
  65.     /**
  66.      * {@inheritdoc}
  67.      */
  68.     public function dispatchPostEvent(
  69.         string $eventName,
  70.         RequestConfiguration $requestConfiguration,
  71.         ResourceInterface $resource
  72.     ): ResourceControllerEvent {
  73.         $eventName $requestConfiguration->getEvent() ?: $eventName;
  74.         $metadata $requestConfiguration->getMetadata();
  75.         $event = new ResourceControllerEvent($resource);
  76.         $this->eventDispatcher->dispatch(sprintf('%s.%s.post_%s'$metadata->getApplicationName(), $metadata->getName(), $eventName), $event);
  77.         return $event;
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function dispatchInitializeEvent(
  83.         string $eventName,
  84.         RequestConfiguration $requestConfiguration,
  85.         ResourceInterface $resource
  86.     ): ResourceControllerEvent {
  87.         $eventName $requestConfiguration->getEvent() ?: $eventName;
  88.         $metadata $requestConfiguration->getMetadata();
  89.         $event = new ResourceControllerEvent($resource);
  90.         $this->eventDispatcher->dispatch(
  91.             sprintf('%s.%s.initialize_%s'$metadata->getApplicationName(), $metadata->getName(), $eventName),
  92.             $event
  93.         );
  94.         return $event;
  95.     }
  96. }