vendor/vich/uploader-bundle/src/EventListener/Doctrine/BaseListener.php line 53

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\EventListener\Doctrine;
  3. use Doctrine\Common\EventSubscriber;
  4. use Vich\UploaderBundle\Adapter\AdapterInterface;
  5. use Vich\UploaderBundle\Handler\UploadHandler;
  6. use Vich\UploaderBundle\Metadata\MetadataReader;
  7. use Vich\UploaderBundle\Util\ClassUtils;
  8. /**
  9.  * BaseListener.
  10.  *
  11.  * @author Kévin Gomez <contact@kevingomez.fr>
  12.  */
  13. abstract class BaseListener implements EventSubscriber
  14. {
  15.     /**
  16.      * @var string
  17.      */
  18.     protected $mapping;
  19.     /**
  20.      * @var AdapterInterface
  21.      */
  22.     protected $adapter;
  23.     /**
  24.      * @var MetadataReader
  25.      */
  26.     protected $metadata;
  27.     /**
  28.      * @var UploadHandler
  29.      */
  30.     protected $handler;
  31.     public function __construct(string $mappingAdapterInterface $adapterMetadataReader $metadataUploadHandler $handler)
  32.     {
  33.         $this->mapping $mapping;
  34.         $this->adapter $adapter;
  35.         $this->metadata $metadata;
  36.         $this->handler $handler;
  37.     }
  38.     /**
  39.      * Checks if the given object is uploadable using the current mapping.
  40.      *
  41.      * @param object $object The object to test
  42.      */
  43.     protected function isUploadable($object): bool
  44.     {
  45.         return $this->metadata->isUploadable(ClassUtils::getClass($object), $this->mapping);
  46.     }
  47.     /**
  48.      * Returns a list of uploadable fields for the given object and mapping.
  49.      *
  50.      * @param object $object The object to use
  51.      *
  52.      * @return array|string[] A list of field names
  53.      *
  54.      * @throws \Vich\UploaderBundle\Exception\MappingNotFoundException
  55.      */
  56.     protected function getUploadableFields($object): array
  57.     {
  58.         $fields $this->metadata->getUploadableFields(ClassUtils::getClass($object), $this->mapping);
  59.         return \array_map(static function (array $data): string {
  60.             return $data['propertyName'];
  61.         }, $fields);
  62.     }
  63. }