<?php
namespace App\Entity;
use App\Repository\ImageRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=ImageRepository::class)
*
* @ORM\HasLifecycleCallbacks()
*
* @Vich\Uploadable
*/
class Image {
use MetaTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $image;
/**
* @Vich\UploadableField(mapping="images", fileNameProperty="image")
*/
private $imageFile;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="images")
*/
private $product;
public function getId(): ?int {
return $this->id;
}
public function getImage(): ?string {
return $this->image;
}
public function setImage(?string $image): self {
$this->image = $image;
return $this;
}
public function getImageFile(): ?File {
return $this->imageFile;
}
public function setImageFile(?File $imageFile): self {
$this->imageFile = $imageFile;
if ($this->imageFile instanceof File) {
$this->modifiedAt = new \DateTime();
}
return $this;
}
public function getProduct(): ?Product {
return $this->product;
}
public function setProduct(?Product $product): self {
$this->product = $product;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setDefaults(): self {
return $this
->setCreatedAt(new \DateTime())
;
}
/**
* @ORM\PreUpdate
*/
public function setModified(): self {
return $this
->setModifiedAt(new \DateTime())
;
}
}