<?php
namespace MLDev\CatalogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use MLDev\BaseBundle\Entity\Traits\Timestampable;
use Symfony\Component\HttpFoundation\File\File;
use MLDev\CatalogBundle\Repository\ProductDocumentRepository;
use function file_exists;
/**
* @ORM\Table(name="MLDev_Product_Document")
* @ORM\Entity(repositoryClass=ProductDocumentRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class ProductDocument
{
use Timestampable;
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", name="title", length=50)
*/
protected $title;
/**
* @ORM\Column(type="string", name="name", length=50)
*/
protected $name;
/**
* @ORM\Column(type="string", name="path", length=255)
*/
protected $path;
/**
* @ORM\Column(type="string", name="uri", length=255)
*/
protected $uri;
/**
* @ORM\ManyToOne(targetEntity="MLDev\CatalogBundle\Entity\Product", inversedBy="documents", cascade={"persist"})
* @ORM\JoinColumn(name="product_id", referencedColumnName="id")
*/
protected $product;
/**
* @var File|null
*/
protected $file;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle($title): void
{
$this->title = $title;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): void
{
$this->name = $name;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): void
{
$this->path = $path;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): void
{
$this->product = $product;
}
public function getFile(): ?File
{
if ($this->file instanceof File) {
return $this->file;
}
if (file_exists($this->path)) {
return new File($this->path);
}
return null;
}
public function setFile(File $file): void
{
$this->file = $file;
}
public function getUri(): ?string
{
return $this->uri;
}
public function setUri(?string $uri)
{
$this->uri = $uri;
}
}