GPU Enitty type cleanup for enum values

This commit is contained in:
Timothy Warren 2022-10-19 12:40:07 -04:00
parent 2fd60cb4b3
commit 827ee8a8eb
22 changed files with 153 additions and 339 deletions

24
composer.lock generated
View File

@ -1451,16 +1451,16 @@
},
{
"name": "friendsofphp/proxy-manager-lts",
"version": "v1.0.12",
"version": "v1.0.13",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/proxy-manager-lts.git",
"reference": "8419f0158715b30d4b99a5bd37c6a39671994ad7"
"reference": "88354616f4cf4f6620910fd035e282173ba453e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/8419f0158715b30d4b99a5bd37c6a39671994ad7",
"reference": "8419f0158715b30d4b99a5bd37c6a39671994ad7",
"url": "https://api.github.com/repos/FriendsOfPHP/proxy-manager-lts/zipball/88354616f4cf4f6620910fd035e282173ba453e8",
"reference": "88354616f4cf4f6620910fd035e282173ba453e8",
"shasum": ""
},
"require": {
@ -1517,7 +1517,7 @@
],
"support": {
"issues": "https://github.com/FriendsOfPHP/proxy-manager-lts/issues",
"source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.12"
"source": "https://github.com/FriendsOfPHP/proxy-manager-lts/tree/v1.0.13"
},
"funding": [
{
@ -1529,7 +1529,7 @@
"type": "tidelift"
}
],
"time": "2022-05-05T09:31:05+00:00"
"time": "2022-10-17T19:48:16+00:00"
},
{
"name": "laminas/laminas-code",
@ -6472,12 +6472,12 @@
"source": {
"type": "git",
"url": "https://github.com/Roave/SecurityAdvisories.git",
"reference": "1d3484a08d3875e28bc2ad66697b0947cd6a2d99"
"reference": "c8e297691dcc30deef58efddd6765c8b7821be56"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/1d3484a08d3875e28bc2ad66697b0947cd6a2d99",
"reference": "1d3484a08d3875e28bc2ad66697b0947cd6a2d99",
"url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/c8e297691dcc30deef58efddd6765c8b7821be56",
"reference": "c8e297691dcc30deef58efddd6765c8b7821be56",
"shasum": ""
},
"conflict": {
@ -6616,7 +6616,7 @@
"gaoming13/wechat-php-sdk": "<=1.10.2",
"genix/cms": "<=1.1.11",
"getgrav/grav": "<1.7.34",
"getkirby/cms": "<3.5.8.1|>=3.6,<3.6.6.1|>=3.7,<3.7.4",
"getkirby/cms": "= 3.8.0|<3.5.8.2|>=3.6,<3.6.6.2|>=3.7,<3.7.5.1",
"getkirby/panel": "<2.5.14",
"getkirby/starterkit": "<=3.7.0.2",
"gilacms/gila": "<=1.11.4",
@ -6731,7 +6731,7 @@
"openid/php-openid": "<2.3",
"openmage/magento-lts": "<19.4.15|>=20,<20.0.13",
"orchid/platform": ">=9,<9.4.4",
"oro/commerce": ">=5,<5.0.4",
"oro/commerce": ">=4.1,<5.0.6",
"oro/crm": ">=1.7,<1.7.4|>=3.1,<4.1.17|>=4.2,<4.2.7",
"oro/platform": ">=1.7,<1.7.4|>=3.1,<3.1.29|>=4.1,<4.1.17|>=4.2,<4.2.8",
"packbackbooks/lti-1-3-php-library": "<5",
@ -6991,7 +6991,7 @@
"type": "tidelift"
}
],
"time": "2022-10-13T20:04:41+00:00"
"time": "2022-10-18T22:04:50+00:00"
},
{
"name": "sebastian/cli-parser",

View File

@ -1,6 +1,4 @@
doctrine_migrations:
migrations_paths:
- '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
# namespace: DoctrineMigrations
'App\Migrations': '%kernel.project_dir%/src/Migrations'
check_database_platform: true

View File

@ -32,6 +32,3 @@ services:
# App\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
_instanceof:
App\Types\AbstractEnumType:
tags: [ 'app.doctrine_enum_type' ]

View File

@ -2,12 +2,14 @@
namespace App\Entity;
use App\Repository\BrandRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'brand', schema: 'collection')]
#[ORM\Entity]
#[ORM\Entity]//(repositoryClass: BrandRepository::class)]
#[ORM\UniqueConstraint(name: 'brand_unq', columns: ["name"])]
class Brand
{
use GetSetTrait;

View File

@ -9,7 +9,6 @@ use Doctrine\ORM\Mapping as ORM;
* Camera
*/
#[ORM\Table(name: 'camera', schema: 'collection')]
#[ORM\Index(columns: ['type_id'], name: 'IDX_747C826FC54C8C93')]
#[ORM\Entity(repositoryClass: CameraRepository::class)]
class Camera
{

View File

@ -11,6 +11,7 @@ use Doctrine\ORM\Mapping as ORM;
*/
trait CameraTrait
{
use GetSetTrait;
use PurchasePriceTrait;
#[ORM\ManyToOne(targetEntity: 'CameraType')]
@ -52,165 +53,4 @@ trait CameraTrait
#[ORM\Column(name: 'received', type: 'boolean', nullable: TRUE)]
private ?bool $received = FALSE;
public function getId(): int
{
return $this->id;
}
public function setType(?CameraType $type = NULL): self
{
$this->type = $type;
return $this;
}
public function getType(): CameraType
{
return $this->type;
}
public function setBrand(string $brand): self
{
$this->brand = $brand;
return $this;
}
public function getBrand(): string
{
return $this->brand;
}
public function setMount(string $mount): self
{
$this->mount = $mount;
return $this;
}
public function getMount(): string
{
return $this->mount;
}
public function setModel(string $model): self
{
$this->model = $model;
return $this;
}
public function getModel(): string
{
return $this->model;
}
public function setIsDigital(bool $isDigital): self
{
$this->isDigital = $isDigital;
return $this;
}
public function getIsDigital(): bool
{
return $this->isDigital;
}
public function setCropFactor(string $cropFactor): self
{
$this->cropFactor = $cropFactor;
return $this;
}
public function getCropFactor(): string
{
return $this->cropFactor;
}
public function setIsWorking(bool $isWorking): self
{
$this->isWorking = $isWorking;
return $this;
}
public function getIsWorking(): bool
{
return $this->isWorking;
}
public function setNotes(?string $notes): self
{
$this->notes = $notes;
return $this;
}
public function getNotes(): string
{
return $this->notes ?? '';
}
public function setSerial(string $serial): self
{
$this->serial = $serial;
return $this;
}
public function getSerial(): string
{
return $this->serial ?? '';
}
public function setFormerlyOwned(bool $formerlyOwned): self
{
$this->formerlyOwned = $formerlyOwned;
return $this;
}
public function getFormerlyOwned(): bool
{
return $this->formerlyOwned;
}
public function setBatteryType(string $batteryType): self
{
$this->batteryType = $batteryType;
return $this;
}
public function getBatteryType(): string
{
return $this->batteryType ?? '';
}
public function setFilmFormat(string $filmFormat): self
{
$this->filmFormat = $filmFormat;
return $this;
}
public function getFilmFormat(): string
{
return $this->filmFormat ?? '';
}
public function setReceived(bool $received): self
{
$this->received = $received;
return $this;
}
public function getReceived(): bool
{
return $this->received;
}
}

View File

@ -40,40 +40,84 @@ class Gpu
#[ORM\Column(name: 'alternate_model_name', nullable: TRUE)]
private ?string $alternateModelName = '';
#[ORM\Column(name: 'card_key', type: SlotKeyEnumType::NAME, nullable: TRUE, enumType: SlotKeyEnum::class)]
#[ORM\Column(
name: 'card_key',
type: 'string',
enumType: SlotKeyEnum::class,
options: array(
'comment' => "The shape of the card connector",
'default' => "PCIe x16"
)
)]
private SlotKeyEnum $cardKey = SlotKeyEnum::PCIE_X16;
#[ORM\Column(name: 'bus_interface', type: CardBusEnumType::NAME, nullable: TRUE, enumType: CardBusEnum::class)]
#[ORM\Column(
name: 'bus_interface',
type: 'string',
nullable: TRUE,
enumType: CardBusEnum::class,
options: array('comment' => "The type of electrical bus this card uses")
)]
private ?CardBusEnum $busInterface;
#[ORM\Column(name: 'slot_width')]
private int $slotWidth = 1;
#[ORM\Column(
name: 'slot_span',
options: array(
'comment' => "How many expansion slots the card occupies",
'default' => 1,
),
)]
private int $slotSpan = 1;
#[ORM\Column(name: 'molex_power')]
#[ORM\Column(name: 'molex_power', options: array('default' => 0))]
private int $molexPower = 0;
#[ORM\Column(name: 'pcie_6_pin')]
#[ORM\Column(name: 'pcie_6_pin', options: array('default' => 0))]
private int $pcie6power = 0;
#[ORM\Column(name: 'pcie_8_pin')]
#[ORM\Column(name: 'pcie_8_pin', options: array('default' => 0))]
private int $pcie8power = 0;
#[ORM\Column(name: 'tdp', nullable: TRUE)]
#[ORM\Column(
name: 'tdp',
nullable: TRUE,
options: array('comment' => "Thermal Design Power (in Watts)")
)]
private ?int $tdp = 0;
#[ORM\Column(name: 'base_clock', nullable: TRUE)]
#[ORM\Column(
name: 'base_clock',
nullable: TRUE,
options: array('comment' => "Base speed of the gpu core, in MHz")
)]
private ?int $baseClock;
#[ORM\Column(name: 'boost_clock', nullable: TRUE)]
#[ORM\Column(
name: 'boost_clock',
nullable: TRUE,
options: array('comment' => "GPU core boost clock, in MHz")
)]
private ?int $boostClock;
#[ORM\Column(name: 'memory_clock', nullable: TRUE)]
#[ORM\Column(
name: 'memory_clock',
nullable: TRUE,
options: array('comment' => "Clock speed of the VRAM, in MHz")
)]
private ?int $memoryClock;
#[ORM\Column(name: 'memory_size', nullable: TRUE)]
#[ORM\Column(
name: 'memory_size',
nullable: TRUE,
options: array('comment' => 'VRAM size, in MiB')
)]
private ?int $memorySize;
#[ORM\Column(name: 'memory_bus', nullable: TRUE)]
#[ORM\Column(
name: 'memory_bus',
nullable: TRUE,
options: array("comment" => 'The width of the memory bus in bits')
)]
private ?int $memoryBus;
#[ORM\Column(name: 'memory_type', nullable: TRUE)]
@ -112,13 +156,13 @@ class Gpu
#[ORM\Column(name: 'shader_model', nullable: TRUE)]
private ?string $shaderModel;
#[ORM\Column(name: 'link')]
private string $link;
#[ORM\Column(name: 'link', nullable: TRUE)]
private ?string $link;
#[ORM\Column(name: 'count', nullable: FALSE)]
#[ORM\Column(name: 'count', nullable: FALSE, options: array('default' => 1))]
private int $count = 1;
#[ORM\Column(name: 'acquired')]
#[ORM\Column(name: 'acquired', nullable: FALSE, options: array('default' => true))]
private bool $acquired;
#[ORM\Column(name: 'notes', type: 'text', nullable: TRUE)]

View File

@ -18,7 +18,7 @@ class GpuCore implements Stringable
#[ORM\ManyToOne(targetEntity: 'Brand')]
#[ORM\OrderBy(['name' => 'asc'])]
#[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id')]
#[ORM\JoinColumn(name: 'brand_id', referencedColumnName: 'id', nullable: FALSE)]
private Brand $brand;
#[ORM\Column(name: 'name')]
@ -27,16 +27,16 @@ class GpuCore implements Stringable
#[ORM\Column(name: 'variant', nullable: TRUE)]
private ?string $variant;
#[ORM\Column(name: 'generation_name')]
#[ORM\Column(name: 'generation_name', nullable: TRUE)]
private string $generationName;
#[ORM\Column(name: 'generation_link', nullable: TRUE)]
private ?string $generationLink = '';
#[ORM\Column(name: 'architecture')]
#[ORM\Column(name: 'architecture', nullable: TRUE)]
private string $architecture;
#[ORM\Column(name: 'architecture_link')]
#[ORM\Column(name: 'architecture_link', nullable: TRUE)]
private string $architectureLink;
#[ORM\Column(name: 'process_node', nullable: TRUE)]

View File

@ -9,7 +9,6 @@ use Doctrine\ORM\Mapping as ORM;
* Camera.previouslyOwnedCamera
*/
#[ORM\Table(name: 'previously_owned_camera', schema: 'collection')]
#[ORM\Index(name: 'IDX_6EF94C6BC54C8C93', columns: ['type_id'])]
#[ORM\Entity(repositoryClass: CameraRepository::class)]
class PreviouslyOwnedCamera
{

View File

@ -47,7 +47,7 @@ class GpuType extends AbstractType {
'choices' => CardBusEnum::getGroups(),
'choice_label' => fn(UnitEnum $choice): string => $choice->value,
])
->add('slotWidth')
->add('slotSpan')
->add('molexPower', NULL, ['label' => 'Molex Power Connectors'])
->add('pcie6power', NULL, ['label' => 'PCIe 6-pin Power Connectors'])
->add('pcie8power', NULL, ['label' => 'PCIe 8-pin Power Connectors'])

View File

@ -11,15 +11,12 @@
namespace App;
use App\Types\AbstractEnumType;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel implements CompilerPassInterface
class Kernel extends BaseKernel
{
use MicroKernelTrait;
@ -37,19 +34,4 @@ class Kernel extends BaseKernel implements CompilerPassInterface
$routes->import('../config/{routes}/*.yaml');
$routes->import('../config/{routes}.yaml');
}
public function process(ContainerBuilder $container)
{
$typesDefinition = [];
if ($container->hasParameter('doctrine.dbal.connection_factory.types')) {
$typesDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');
}
$taggedEnums = $container->findTaggedServiceIds('app.doctrine_enum_type');
foreach ($taggedEnums as $enumType => $definition) {
$typesDefinition[$enumType::NAME] = ['class' => $enumType];
}
$container->setParameter('doctrine.dbal.connection_factory.types', $typesDefinition);
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221014203914 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE collection.gpu ALTER card_key TYPE character varying');
$this->addSql('ALTER TABLE collection.gpu ALTER bus_interface TYPE character varying');
}
public function down(Schema $schema): void
{
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221014212753 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
}
}

View File

@ -2,17 +2,10 @@
namespace App\Repository;
use App\Entity\Brand;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
class BrandRepository extends ServiceEntityRepository {
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Brand::class);
}
class BrandRepository extends EntityRepository {
public function filterByCategory(string $category): Query
{
$em = $this->getEntityManager();

View File

@ -1,44 +0,0 @@
<?php declare(strict_types=1);
namespace App\Types;
use BackedEnum;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
abstract class AbstractEnumType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'TEXT';
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
{
if (is_scalar($value))
{
return $value;
}
if ($value instanceof BackedEnum)
{
return $value->value;
}
return $value;
}
public function convertToPHPValue($value, AbstractPlatform $platform): mixed
{
if (false === enum_exists($this::getEnumsClass(), true))
{
throw new \LogicException("This class should be an enum");
}
$enum = $this::getEnumsClass();
return $enum::from($value);
}
abstract public static function getEnumsClass(): string;
}

View File

@ -1,19 +0,0 @@
<?php declare(strict_types=1);
namespace App\Types;
enum BusInterface: string {
case PCI = 'PCI';
case ISA = 'ISA';
case VLB = 'VLB (Vesa Local Bus)';
case AGP = 'AGP';
case AGPX2 = 'AGP 2x';
case AGPX4 = 'AGP 4x';
case AGPX8 = 'AGP 8x';
}

View File

@ -1,19 +0,0 @@
<?php declare(strict_types=1);
namespace App\Types;
use App\Enum\CardBusEnum;
class CardBusEnumType extends AbstractEnumType {
public const NAME = 'cardBusEnum';
public static function getEnumsClass(): string
{
return CardBusEnum::class;
}
public function getName(): string
{
return self::NAME;
}
}

View File

@ -1,19 +0,0 @@
<?php declare(strict_types=1);
namespace App\Types;
use App\Enum\SlotKeyEnum;
class SlotKeyEnumType extends AbstractEnumType {
public const NAME = 'slotKeyEnum';
public static function getEnumsClass(): string
{
return SlotKeyEnum::class;
}
public function getName(): string
{
return self::NAME;
}
}

View File

@ -33,7 +33,7 @@
{{ form_row(edit_form.cardKey) }}
{{ form_row(edit_form.busInterface) }}
{{ form_row(edit_form.slotWidth) }}
{{ form_row(edit_form.slotSpan) }}
</fieldset>
<fieldset class="large primary callout">

View File

@ -105,7 +105,7 @@
<td>{{ gpu.alternateModelName }}</td>
<td>{{ gpu.cardKey.value }}</td>
<td>{{ gpu.busInterface.value }}</td>
<td>{{ gpu.slotWidth }}</td>
<td>{{ gpu.slotSpan }}</td>
<td>
{% if gpu.pcie6power > 0 or gpu.pcie8power > 0 %}
{% if gpu.pcie6power > 0 %}

View File

@ -32,7 +32,7 @@
{{ form_row(form.cardKey) }}
{{ form_row(form.busInterface) }}
{{ form_row(form.slotWidth) }}
{{ form_row(form.slotSpan) }}
</fieldset>
<fieldset class="large primary callout">

View File

@ -49,8 +49,8 @@
<td>{{ gpu.busInterface.value }}</td>
</tr>
<tr>
<th>SlotWidth</th>
<td>{{ gpu.slotWidth }}</td>
<th>slotSpan</th>
<td>{{ gpu.slotSpan }}</td>
</tr>
<tr>
<th>MolexPower</th>