<?php
namespace App\Entity\ContentDistribution;
use App\Utility\ReflectionHelper;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="recurrent_job_persistent_values"
* )
*/
class RecurrentJobPersistentValue
{
public const NAME_AGENTUR_FUER_ARBEIT_SHORT_ID = 'agenturFuerArbeitShortId';
public const TYPE_STRING = 0;
public const TYPE_FLOAT = 1;
public const TYPE_BOOL = 2;
public const NAMES_TO_TYPES = [
self::NAME_AGENTUR_FUER_ARBEIT_SHORT_ID => self::TYPE_STRING,
];
/** @throws Exception */
public static function createWithStringValue(string $recurrentJobId, string $name, string $stringValue): self
{
if (!ReflectionHelper::hasConstWithValue(self::class, 'NAME_', $name)) {
throw new Exception("Not a name: '{$name}'.");
}
if (self::NAMES_TO_TYPES[$name] !== self::TYPE_STRING) {
throw new Exception("Value type for name {$name} cannot be 'string'.");
}
$distributionValue = new self();
$distributionValue->recurrentJobId = $recurrentJobId;
$distributionValue->name = $name;
$distributionValue->stringValue = $stringValue;
return $distributionValue;
}
/** @throws Exception */
public static function createWithFloatValue(string $recurrentJobId, string $name, float $floatValue): self
{
if (!ReflectionHelper::hasConstWithValue(self::class, 'NAME_', $name)) {
throw new Exception("Not a name: '{$name}'.");
}
if (self::NAMES_TO_TYPES[$name] !== self::TYPE_FLOAT) {
throw new Exception("Value type for name {$name} cannot be 'float'.");
}
$distributionValue = new self();
$distributionValue->recurrentJobId = $recurrentJobId;
$distributionValue->name = $name;
$distributionValue->floatValue = $floatValue;
return $distributionValue;
}
/** @throws Exception */
public static function createWithBoolValue(string $recurrentJobId, string $name, float $boolValue): self
{
if (!ReflectionHelper::hasConstWithValue(self::class, 'NAME_', $name)) {
throw new Exception("Not a name: '{$name}'.");
}
if (self::NAMES_TO_TYPES[$name] !== self::TYPE_BOOL) {
throw new Exception("Value type for name {$name} cannot be 'float'.");
}
$distributionValue = new self();
$distributionValue->recurrentJobId = $recurrentJobId;
$distributionValue->name = $name;
$distributionValue->boolValue = $boolValue;
return $distributionValue;
}
public static function isValidName(string $name): bool
{
return array_key_exists($name, self::NAMES_TO_TYPES);
}
/**
* @ORM\Id
*
* @ORM\Column(type="string", nullable=false)
*/
private string $name;
public function getName(): string
{
return $this->name;
}
/**
* @ORM\Column(type="string", name="string_value", nullable=true, length=4096)
*/
private ?string $stringValue;
public function getStringValue(): ?string
{
return $this->stringValue;
}
/** @throws Exception */
public function setStringValue(?string $stringValue): void
{
if (self::NAMES_TO_TYPES[$this->name] !== self::TYPE_STRING) {
throw new Exception("Value type for name {$this->name} cannot be 'string'.");
}
$this->stringValue = $stringValue;
}
/**
* @ORM\Column(type="float", name="float_value", nullable=true)
*/
private ?float $floatValue;
public function getFloatValue(): ?float
{
return $this->floatValue;
}
/** @throws Exception */
public function setFloatValue(?float $floatValue): void
{
if (self::NAMES_TO_TYPES[$this->name] !== self::TYPE_FLOAT) {
throw new Exception("Value type for name {$this->name} cannot be 'float'.");
}
$this->floatValue = $floatValue;
}
/**
* @ORM\Column(type="boolean", name="bool_value", nullable=true)
*/
private ?bool $boolValue;
public function getBoolValue(): ?bool
{
return $this->boolValue;
}
/** @throws Exception */
public function setBoolValue(?bool $boolValue): void
{
if (self::NAMES_TO_TYPES[$this->name] !== self::TYPE_BOOL) {
throw new Exception("Value type for name {$this->name} cannot be 'bool'.");
}
$this->boolValue = $boolValue;
}
/**
* @ORM\Id
*
* @ORM\Column(type="string", name="recurrent_job_id", nullable=true, length=128)
*/
private string $recurrentJobId;
public function getRecurrentJobId(): string
{
return $this->recurrentJobId;
}
public function setRecurrentJobId(string $recurrentJobId): void
{
$this->recurrentJobId = $recurrentJobId;
}
}