ArdentParameterBundle/Entity/Parameter.php

71 lines
1.3 KiB
PHP
Raw Normal View History

2019-05-23 17:04:48 +02:00
<?php
2020-07-25 17:40:08 +02:00
namespace Ardent\ParameterBundle\Entity;
2019-05-23 17:04:48 +02:00
use Doctrine\DBAL\Types\TextType;
2019-05-23 17:04:48 +02:00
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
2019-05-23 17:04:48 +02:00
/**
* @ORM\Entity
* @ORM\Table(name="parameter_bundle_parameters")
*/
class Parameter
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private ?int $id;
2019-05-23 17:04:48 +02:00
/**
* @ORM\Column(type="string")
*/
private ?string $name;
2019-05-23 17:04:48 +02:00
/**
* @ORM\Column(type="string")
*/
private mixed $value;
2019-05-23 17:04:48 +02:00
public function getId(): int
2019-05-23 17:04:48 +02:00
{
return $this->id;
}
public function getName(): string
2019-05-23 17:04:48 +02:00
{
return $this->name;
}
public function setName(string $name): self
2019-05-23 17:04:48 +02:00
{
$this->name = $name;
return $this;
}
public function getValue(): mixed
2019-05-23 17:04:48 +02:00
{
return $this->value;
}
static function parseValue(mixed $value, string $type): mixed
{
return match ($type) {
NumberType::class => intval($value),
CheckboxType::class => boolval($value),
default => $value,
};
}
public function setValue(mixed $value): self
2019-05-23 17:04:48 +02:00
{
$this->value = $value;
return $this;
}
}