collection-crud/src/Entity/Socket.php

54 lines
1.4 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Enum\SocketType;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
/**
* @see https://en.wikipedia.org/wiki/CPU_socket
*/
#[ORM\Table(name: 'socket', schema: 'collection')]
#[ORM\Entity]
class Socket implements Stringable {
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: SocketType::class,
)]
private SocketType $type = SocketType::PIN_GRID_ARRAY;
// ------------------------------------------------------------------------
public function __toString(): string
{
$name = (empty($this->otherName)) ? $this->name : "$this->name/$this->otherName";
return (string) "{$name} ({$this->type->value} $this->pinCount)";
}
}