|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\RuntimeResource; |
| 15 | + |
| 16 | +use Doctrine\ORM\Mapping as ORM; |
| 17 | + |
| 18 | +#[ORM\Entity] |
| 19 | +#[ORM\Table(name: 'runtime_attribute_value')] |
| 20 | +class AttributeValue |
| 21 | +{ |
| 22 | + public const FIELDS = [ |
| 23 | + 'string' => 'stringValue', |
| 24 | + 'enum' => 'stringValue', |
| 25 | + 'text' => 'textValue', |
| 26 | + 'integer' => 'integerValue', |
| 27 | + 'float' => 'floatValue', |
| 28 | + 'boolean' => 'booleanValue', |
| 29 | + 'datetime' => 'datetimeValue', |
| 30 | + 'reference' => 'referenceId', |
| 31 | + ]; |
| 32 | + |
| 33 | + #[ORM\Id] |
| 34 | + #[ORM\GeneratedValue] |
| 35 | + #[ORM\Column] |
| 36 | + private ?int $id = null; |
| 37 | + |
| 38 | + #[ORM\Column(name: 'string_value', nullable: true)] |
| 39 | + private ?string $stringValue = null; |
| 40 | + |
| 41 | + #[ORM\Column(name: 'text_value', type: 'text', nullable: true)] |
| 42 | + private ?string $textValue = null; |
| 43 | + |
| 44 | + #[ORM\Column(name: 'integer_value', nullable: true)] |
| 45 | + private ?int $integerValue = null; |
| 46 | + |
| 47 | + #[ORM\Column(name: 'float_value', nullable: true)] |
| 48 | + private ?float $floatValue = null; |
| 49 | + |
| 50 | + #[ORM\Column(name: 'boolean_value', nullable: true)] |
| 51 | + private ?bool $booleanValue = null; |
| 52 | + |
| 53 | + #[ORM\Column(name: 'datetime_value', nullable: true)] |
| 54 | + private ?\DateTimeImmutable $datetimeValue = null; |
| 55 | + |
| 56 | + #[ORM\Column(name: 'reference_id', nullable: true)] |
| 57 | + private ?int $referenceId = null; |
| 58 | + |
| 59 | + public function __construct( |
| 60 | + #[ORM\ManyToOne(inversedBy: 'values')] |
| 61 | + #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] |
| 62 | + private EntityRow $entity, |
| 63 | + #[ORM\ManyToOne] |
| 64 | + #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')] |
| 65 | + private AttributeDefinition $attribute, |
| 66 | + #[ORM\Column] |
| 67 | + private int $position, |
| 68 | + mixed $value, |
| 69 | + ) { |
| 70 | + $this->{self::FIELDS[$attribute->getType()]} = $value; |
| 71 | + } |
| 72 | + |
| 73 | + public function getAttribute(): AttributeDefinition |
| 74 | + { |
| 75 | + return $this->attribute; |
| 76 | + } |
| 77 | + |
| 78 | + public function getValue(): mixed |
| 79 | + { |
| 80 | + return $this->{self::FIELDS[$this->attribute->getType()]}; |
| 81 | + } |
| 82 | +} |
0 commit comments