collection-crud/src/Entity/Socket.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2022-10-20 11:07:27 -04:00
<?php declare(strict_types=1);
namespace App\Entity;
2023-07-21 10:23:16 -04:00
use App\Enum\SocketType;
2022-11-17 15:32:57 -05:00
use Doctrine\Common\Collections\Collection;
2022-10-20 11:07:27 -04:00
use Doctrine\ORM\Mapping as ORM;
2023-07-21 10:50:58 -04:00
use Stringable;
2022-10-20 11:07:27 -04:00
/**
* @see https://en.wikipedia.org/wiki/CPU_socket
*/
#[ORM\Table(name: 'socket', schema: 'collection')]
#[ORM\Entity]
2023-07-21 10:50:58 -04:00
class Socket implements Stringable {
2022-11-17 15:32:57 -05:00
use GetSet;
2022-10-20 11:07:27 -04:00
#[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)]
2022-10-25 14:52:58 -04:00
private ?string $otherName = NULL;
2022-10-20 11:07:27 -04:00
#[ORM\Column(name: 'pin_count', type: 'integer', nullable: FALSE)]
private int $pinCount;
2022-11-17 15:32:57 -05:00
#[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;
2022-10-20 11:07:27 -04:00
#[ORM\Column(
name: 'socket_type',
type: 'string',
2023-07-21 10:23:16 -04:00
enumType: SocketType::class,
2022-10-20 11:07:27 -04:00
)]
2023-07-21 10:23:16 -04:00
private SocketType $type = SocketType::PIN_GRID_ARRAY;
2022-10-20 11:07:27 -04:00
2022-11-17 15:32:57 -05:00
// ------------------------------------------------------------------------
2022-10-20 11:07:27 -04:00
public function __toString(): string
{
2023-07-21 10:50:58 -04:00
$name = (empty($this->otherName)) ? $this->name : "$this->name/$this->otherName";
2022-10-20 11:07:27 -04:00
2023-07-21 10:50:58 -04:00
return (string) "{$name} ({$this->type->value} $this->pinCount)";
2022-10-20 11:07:27 -04:00
}
}