<?php
namespace App\Entity;
use App\Service\CircuitbreakerService;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use ReflectionClass;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="circuitbreaker_events",
* indexes={
*
* @ORM\Index(name="event_category_occured_at_idx", columns={"event_category", "occured_at"}),
* @ORM\Index(name="ec_esc_oa_io_idx", columns={"event_category", "event_sub_category", "is_open"})
* }
* )
*/
class CircuitbreakerEvent
{
/**
* @var string
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
protected $id;
/**
* @var int
*
* @ORM\Column(name="event_category", type="smallint", nullable=false)
*/
protected $eventCategory;
/**
* @var string|null
*
* @ORM\Column(name="event_sub_category", type="string", length=128, nullable=true)
*/
protected $eventSubCategory;
/**
* @var DateTime
*
* @ORM\Column(name="occured_at", type="datetime", nullable=false)
*/
protected $occuredAt;
/**
* @var bool
*
* @ORM\Column(name="is_open", type="boolean", nullable=false)
*/
protected $isOpen;
public function getId(): string
{
return $this->id;
}
public function getEventCategory(): int
{
return $this->eventCategory;
}
/**
* @throws Exception
*/
public function getEventCategoryTitle(): string
{
$refl = new ReflectionClass(CircuitbreakerService::class);
$constants = $refl->getConstants();
foreach ($constants as $constantName => $constantValue) {
if (substr($constantName, 0, 15) === 'EVENT_CATEGORY_' && $constantValue === $this->getEventCategory()) {
return strtolower(str_replace('_', '-', substr($constantName, 15)));
}
}
throw new Exception('Cannot resolve title for event category ' . $this->getEventCategory());
}
public function setEventCategory(int $eventCategory): void
{
$this->eventCategory = $eventCategory;
}
public function getEventSubCategory(): string
{
return $this->eventSubCategory;
}
public function setEventSubCategory(string $eventSubCategory): void
{
$this->eventSubCategory = $eventSubCategory;
}
public function getOccuredAt(): DateTime
{
return $this->occuredAt;
}
public function setOccuredAt(DateTime $occuredAt): void
{
$this->occuredAt = $occuredAt;
}
public function isOpen(): bool
{
return $this->isOpen;
}
public function setIsOpen(bool $isOpen): void
{
$this->isOpen = $isOpen;
}
}