<?phpnamespace Whater\Domain\Media\Model;use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;use Ramsey\Uuid\Uuid;use Whater\Domain\Common\Exception\InvalidUUIDException;use Whater\Domain\User\Model\User;use Whater\Domain\Product\Model\Product;/** * Class ProductImage * * @package Whater\Domain\Media\Model */class ProductImage implements ContainsRecordedEvents{ use EventRecorderCapabilities; /** * @var string */ private $uuid; /** * @var null|\DateTime */ private $createdAt; /** * @var null|\DateTime */ private $updatedAt; /** * @var Product */ private $product; /** * @var User */ private $createdBy; /** * @var string */ private $fileName; /** * @var integer */ private $fileSize; /** * @var string */ private $fileMimeType; /** * @var string */ private $fileOriginalname; /** * @var array */ private $fileDimensions; /** * @var File * NOTE: This is not a mapped field of entity metadata, just a simple property. */ private $fileProductImage; public function __construct( string $productImageId = null, Product $product = null, User $createdBy = null ) { try { $this->uuid = Uuid::fromString($productImageId ?: Uuid::uuid4())->toString(); } catch (\InvalidArgumentException $e) { throw new InvalidUUIDException(); } $this->createdAt = new \DateTime(); $this->product = $product; $this->createdBy = $createdBy; $this->updatedAt = new \DateTime(); } public function setData(Product $product, User $createdBy) { $this->product = $product; $this->createdBy = $createdBy; $this->updatedAt = new \DateTime(); } /** * @return string */ public function id(): string { return $this->uuid; } /** * @return \DateTime */ public function createdAt(): \DateTime { return $this->createdAt; } /** * @return \DateTime */ public function updatedAt(): \DateTime { return $this->updatedAt; } /** * @return Product */ public function product(): Product { return $this->product; } /** * @return User|null */ public function createdBy(): ?User { return $this->createdBy; } public function setFileName(?string $fileName): void { $this->fileName = $fileName; } public function getFileName(): ?string { return $this->fileName; } public function setFileSize(?int $fileSize): void { $this->fileSize = $fileSize; } public function getFileSize(): ?int { return $this->fileSize; } public function setFileMimeType(?string $fileMimeType): void { $this->fileMimeType = $fileMimeType; } public function getFileMimeType(): ?string { return $this->fileMimeType; } public function setFileOriginalname(?string $fileOriginalname): void { $this->fileOriginalname = $fileOriginalname; } public function getFileOriginalname(): ?string { return $this->fileOriginalname; } public function setFileDimensions(?array $fileDimensions): void { $this->fileDimensions = $fileDimensions; } public function getFileDimensions(): ?array { return $this->fileDimensions; } public function setFileProductImage($fileProductImage): void { $this->fileProductImage = $fileProductImage; } public function getFileProductImage() { return $this->fileProductImage; } public function serialize() { return serialize(array( $this->uuid )); } public function unserialize($serialized) { list( $this->uuid ) = unserialize($serialized); } /** * @return bool */ public function equals(ProductImage $productImage) { return $this->id() === $productImage->id(); }}