Files
slotdb/src/Data/Slot/Slot.php
T
2025-03-13 22:24:05 +01:00

75 lines
1.6 KiB
PHP

<?php
namespace SlotDb\SlotDb\Data\Slot;
use Doctrine\ORM\Mapping as ORM;
use ArrayIterator;
use IteratorAggregate;
use JsonSerializable;
use SlotDb\SlotDb\Data\Group\Group;
use Traversable;
#[ORM\Table(name: 'slots')]
#[ORM\Entity(repositoryClass: SlotRepository::class)]
class Slot implements IteratorAggregate, JsonSerializable
{
#[ORM\Id()]
#[ORM\GeneratedValue()]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 96, unique: true)]
private string $slotId;
#[ORM\ManyToOne(targetEntity: Group::class, inversedBy: 'slots')]
private ?Group $group = null;
#[ORM\Column(type: 'string', length: 96)]
private string $name;
#[ORM\Column(type: 'json', nullable: true)]
private array $props = [];
public function __construct(
string $slotId,
string $name,
)
{
$this->slotId = $slotId;
$this->name = $name;
$this->props = [];
}
public function getSlotId(): string
{
return $this->slotId;
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->props);
}
public function jsonSerialize(): mixed
{
return [
'_id' => $this->id,
'_slot' => $this->slotId,
'_name' => $this->name,
'_group' => $this->group?->getGroupId(),
...$this->props,
];
}
public function getProperties(): array
{
return $this->props;
}
public function setProperties(array $properties): self
{
$this->props = $properties;
return $this;
}
}