vendor/vich/uploader-bundle/src/Entity/File.php line 5

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\Entity;
  3. class File
  4. {
  5.     /**
  6.      * @var string
  7.      */
  8.     protected $name;
  9.     /**
  10.      * @var string
  11.      */
  12.     protected $originalName;
  13.     /**
  14.      * @var string
  15.      */
  16.     protected $mimeType;
  17.     /**
  18.      * @var int
  19.      */
  20.     protected $size;
  21.     /**
  22.      * @var array<int, int>
  23.      */
  24.     protected $dimensions;
  25.     public function getName(): ?string
  26.     {
  27.         return $this->name;
  28.     }
  29.     public function setName(?string $name): void
  30.     {
  31.         $this->name $name;
  32.     }
  33.     public function getOriginalName(): ?string
  34.     {
  35.         return $this->originalName;
  36.     }
  37.     public function setOriginalName(?string $originalName): void
  38.     {
  39.         $this->originalName $originalName;
  40.     }
  41.     public function getMimeType(): ?string
  42.     {
  43.         return $this->mimeType;
  44.     }
  45.     public function setMimeType(?string $mimeType): void
  46.     {
  47.         $this->mimeType $mimeType;
  48.     }
  49.     public function getSize(): ?int
  50.     {
  51.         return $this->size;
  52.     }
  53.     public function setSize(?int $size): void
  54.     {
  55.         $this->size $size;
  56.     }
  57.     public function getDimensions(): ?array
  58.     {
  59.         return $this->dimensions;
  60.     }
  61.     public function setDimensions(?array $dimensions): void
  62.     {
  63.         $this->dimensions $dimensions;
  64.     }
  65.     /**
  66.      * A simple shortcut to the image width.
  67.      * Similar to `$file->getDimensions()[0]`.
  68.      *
  69.      * @return int|null Returns `null` if dimensions array is itself null
  70.      */
  71.     public function getWidth(): ?int
  72.     {
  73.         return $this->dimensions[0] ?? null;
  74.     }
  75.     /**
  76.      * A simple shortcut to the image height.
  77.      * Similar to `$file->getDimensions()[1]`.
  78.      *
  79.      * @return int|null Returns `null` if dimensions array is itself null
  80.      */
  81.     public function getHeight(): ?int
  82.     {
  83.         return $this->dimensions[1] ?? null;
  84.     }
  85.     /**
  86.      * Format image dimensions for use with html (to avoid layout shifting).
  87.      *
  88.      * Usage in twig template:
  89.      * ```twig
  90.      * <img src="..." alt="..." {{ image.htmlDimensions|raw }}>
  91.      * <!-- Will render: -->
  92.      * <img src="..." alt="..." width="..." height="...">
  93.      * ```
  94.      *
  95.      * @return string|null Returns `null` if dimensions array is itself null
  96.      */
  97.     public function getHtmlDimensions(): ?string
  98.     {
  99.         if (null !== $this->dimensions) {
  100.             return \sprintf('width="%s" height="%s"'$this->getWidth(), $this->getHeight());
  101.         }
  102.         return null;
  103.     }
  104. }