collection-crud/src/Entity/Socket.php

53 lines
1.4 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Enum\SocketTypeEnum;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @see https://en.wikipedia.org/wiki/CPU_socket
*/
#[ORM\Table(name: 'socket', schema: 'collection')]
#[ORM\Entity]
class Socket {
use GetSet;
#[ORM\Column(name: 'id', type: 'integer', nullable: FALSE)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private int $id;
#[ORM\Column(name: 'name', type: 'string', nullable: FALSE)]
private string $name;
#[ORM\Column(name: 'other_name', type: 'string', nullable: TRUE)]
private ?string $otherName = NULL;
#[ORM\Column(name: 'pin_count', type: 'integer', nullable: FALSE)]
private int $pinCount;
#[ORM\ManyToMany(targetEntity: Cpu::class, mappedBy: 'sockets', fetch: 'EXTRA_LAZY')]
private Collection $cpus;
#[ORM\ManyToMany(targetEntity: Motherboard::class, mappedBy: 'sockets', fetch: 'EXTRA_LAZY')]
private Collection $motherboards;
#[ORM\Column(
name: 'socket_type',
type: 'string',
enumType: SocketTypeEnum::class,
)]
private SocketTypeEnum $type = SocketTypeEnum::PIN_GRID_ARRAY;
// ------------------------------------------------------------------------
public function __toString(): string
{
$name = ( ! empty($this->otherName)) ? "$this->name/$this->otherName" : $this->name;
return "$name ({$this->type->value} $this->pinCount)";
}
}