vendor/crea/media-bundle/src/Entity/MediaType.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Crea\MediaBundle\Entity;
  4. use Crea\MediaBundle\Entity\Enum\MediaTypeCodeEnum;
  5. use Crea\MediaBundle\Repository\MediaTypeRepository;
  6. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Stringable;
  11. /**
  12. * @ORM\Entity(repositoryClass=MediaTypeRepository::class)
  13. *
  14. * @ORM\Table(name="media_type")
  15. */
  16. class MediaType implements Stringable, CodeIdentifiedInterface, FileConstraintInterface
  17. {
  18. use LifecycleUserIdentifierTrait;
  19. /**
  20. * @ORM\Id
  21. *
  22. * @ORM\GeneratedValue
  23. *
  24. * @ORM\Column(type="integer")
  25. */
  26. private ?int $id = null;
  27. /**
  28. * @ORM\Column(type="string", length=255, nullable=false)
  29. */
  30. private ?string $label = null;
  31. /**
  32. * @ORM\Column(type="string", nullable=true)
  33. */
  34. private ?string $mimeType = null;
  35. /**
  36. * @var array<string>
  37. *
  38. * @ORM\Column(type="simple_array", nullable=true)
  39. */
  40. private ?array $extensions = [];
  41. /**
  42. * @ORM\Column(type="string", enumType=MediaTypeCodeEnum::class, nullable=false, unique=true)
  43. */
  44. private ?MediaTypeCodeEnum $code = null;
  45. /**
  46. * @ORM\ManyToOne(targetEntity=MediaFamily::class, inversedBy="mediaTypes")
  47. */
  48. private ?MediaFamily $mediaFamily = null;
  49. /**
  50. * @var Collection<int, MediaFile>
  51. *
  52. * @ORM\OneToMany(targetEntity=MediaFile::class, mappedBy="mediaType")
  53. */
  54. private Collection $mediaFiles;
  55. public function __construct()
  56. {
  57. $this->mediaFiles = new ArrayCollection();
  58. }
  59. public function __toString(): string
  60. {
  61. return $this->getLabel() ?: 'MediaType - ('.$this->id.')';
  62. }
  63. public function getId(): ?int
  64. {
  65. return $this->id;
  66. }
  67. public function setId(?int $id): self
  68. {
  69. $this->id = $id;
  70. return $this;
  71. }
  72. public function getLabel(): ?string
  73. {
  74. return $this->label;
  75. }
  76. public function setLabel(?string $label): self
  77. {
  78. $this->label = $label;
  79. return $this;
  80. }
  81. public function getMimeType(): ?string
  82. {
  83. return $this->mimeType;
  84. }
  85. public function setMimeType(?string $mimeType): self
  86. {
  87. $this->mimeType = $mimeType;
  88. return $this;
  89. }
  90. /**
  91. * @return string[]|null
  92. */
  93. public function getExtensions(): ?array
  94. {
  95. return $this->extensions;
  96. }
  97. /**
  98. * @param array<string>|null $extensions
  99. */
  100. public function setExtensions(?array $extensions): self
  101. {
  102. $this->extensions = $extensions;
  103. return $this;
  104. }
  105. public function getCode(): ?MediaTypeCodeEnum
  106. {
  107. return $this->code;
  108. }
  109. public function setCode(?MediaTypeCodeEnum $code): self
  110. {
  111. $this->code = $code;
  112. return $this;
  113. }
  114. public function getMediaFamily(): ?MediaFamily
  115. {
  116. return $this->mediaFamily;
  117. }
  118. public function setMediaFamily(?MediaFamily $mediaFamily): self
  119. {
  120. $this->mediaFamily = $mediaFamily;
  121. return $this;
  122. }
  123. /**
  124. * @return Collection<int, MediaFile>
  125. */
  126. public function getMediaFiles(): Collection
  127. {
  128. return $this->mediaFiles;
  129. }
  130. public function addMediaFile(MediaFile $mediaFile): self
  131. {
  132. if (!$this->mediaFiles->contains($mediaFile)) {
  133. $this->mediaFiles[] = $mediaFile;
  134. $mediaFile->setMediaType($this);
  135. }
  136. return $this;
  137. }
  138. public function removeMediaFile(MediaFile $mediaFile): self
  139. {
  140. if ($this->mediaFiles->removeElement($mediaFile)) {
  141. if ($mediaFile->getMediaType() === $this) {
  142. $mediaFile->setMediaType(null);
  143. }
  144. }
  145. return $this;
  146. }
  147. }