futtern/src/Entity/Vendor.php
2024-02-13 23:02:22 +01:00

84 lines
1.9 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Repository\VendorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: VendorRepository::class)]
class Vendor
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid $id;
#[ORM\Column(length: 50)]
private string|null $name = null;
#[ORM\OneToMany(
mappedBy: 'vendor',
targetEntity: MenuItem::class,
orphanRemoval: true,
)]
private Collection $menuItems;
public function __construct()
{
$this->id = new Ulid;
$this->menuItems = new ArrayCollection;
}
public function getId(): Ulid
{
return $this->id;
}
public function getName(): string|null
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(): Collection
{
return $this->menuItems;
}
public function addMenuItem(MenuItem $menuItem): static
{
if (! $this->menuItems->contains($menuItem)) {
$this->menuItems->add($menuItem);
$menuItem->setVendor($this);
}
return $this;
}
public function removeMenuItem(MenuItem $menuItem): static
{
// set the owning side to null (unless already changed)
if (
$this->menuItems->removeElement($menuItem)
&& $menuItem->getVendor() === $this
) {
$menuItem->setVendor(null);
}
return $this;
}
}