vendor/bitbag/cms-plugin/src/EventListener/MediaUploadListener.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3. * This file was created by developers working at BitBag
  4. * Do you need more information about us and what we do? Visit our https://bitbag.io website!
  5. * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
  6. */
  7. declare(strict_types=1);
  8. namespace BitBag\SyliusCmsPlugin\EventListener;
  9. use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
  10. use BitBag\SyliusCmsPlugin\Resolver\MediaProviderResolverInterface;
  11. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  12. use Webmozart\Assert\Assert;
  13. final class MediaUploadListener
  14. {
  15. /** @var MediaProviderResolverInterface */
  16. private $mediaProviderResolver;
  17. public function __construct(MediaProviderResolverInterface $mediaProviderResolver)
  18. {
  19. $this->mediaProviderResolver = $mediaProviderResolver;
  20. }
  21. public function uploadMedia(ResourceControllerEvent $event): void
  22. {
  23. /** @var MediaInterface|null $media */
  24. $media = $event->getSubject();
  25. Assert::isInstanceOf($media, MediaInterface::class);
  26. $this->mediaProviderResolver->resolveProvider($media)->upload($media);
  27. }
  28. }