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