vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/CatalogPromotion/EventListener/ProductEventListener.php line 37

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\CoreBundle\CatalogPromotion\EventListener;
  12. use Sylius\Component\Core\Event\ProductCreated;
  13. use Sylius\Component\Core\Event\ProductUpdated;
  14. use Sylius\Component\Core\Model\ProductInterface;
  15. use Symfony\Component\EventDispatcher\GenericEvent;
  16. use Symfony\Component\Messenger\MessageBusInterface;
  17. use Webmozart\Assert\Assert;
  18. final class ProductEventListener
  19. {
  20.     public function __construct(private MessageBusInterface $eventBus)
  21.     {
  22.     }
  23.     public function dispatchProductCreatedEvent(GenericEvent $event): void
  24.     {
  25.         $product $event->getSubject();
  26.         Assert::isInstanceOf($productProductInterface::class);
  27.         $this->eventBus->dispatch(new ProductCreated($product->getCode()));
  28.     }
  29.     public function dispatchProductUpdatedEvent(GenericEvent $event): void
  30.     {
  31.         $product $event->getSubject();
  32.         Assert::isInstanceOf($productProductInterface::class);
  33.         $this->eventBus->dispatch(new ProductUpdated($product->getCode()));
  34.     }
  35. }