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

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