vendor/bitbag/banner-plugin/src/EventListener/BannerListener.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file has been created by developers from BitBag.
  4.  * Feel free to contact us once you face any issues or want to start
  5.  * You can find more information about us on https://bitbag.io and write us
  6.  * an email on hello@bitbag.io.
  7.  */
  8. declare(strict_types=1);
  9. namespace BitBag\SyliusBannerPlugin\EventListener;
  10. use BitBag\SyliusBannerPlugin\Entity\BannerInterface;
  11. use BitBag\SyliusBannerPlugin\Uploader\BannerUploaderInterface;
  12. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  13. use Webmozart\Assert\Assert;
  14. final class BannerListener
  15. {
  16.     private BannerUploaderInterface $bannerUploader;
  17.     public function __construct(BannerUploaderInterface $bannerUploader)
  18.     {
  19.         $this->bannerUploader $bannerUploader;
  20.     }
  21.     public function uploadBanner(ResourceControllerEvent $event): void
  22.     {
  23.         $banner $event->getSubject();
  24.         Assert::isInstanceOf($bannerBannerInterface::class);
  25.         $this->bannerUploader->upload($banner);
  26.     }
  27.     public function removeBanner(ResourceControllerEvent $event): void
  28.     {
  29.         $banner $event->getSubject();
  30.         Assert::isInstanceOf($bannerBannerInterface::class);
  31.         if (null !== $banner->getPath()) {
  32.             $this->bannerUploader->remove($banner->getPath());
  33.         }
  34.     }
  35. }