src/App/Entity/CircuitbreakerEvent.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\CircuitbreakerService;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Exception;
  7. use ReflectionClass;
  8. /**
  9. * @ORM\Entity
  10. *
  11. * @ORM\Table(
  12. * name="circuitbreaker_events",
  13. * indexes={
  14. *
  15. * @ORM\Index(name="event_category_occured_at_idx", columns={"event_category", "occured_at"}),
  16. * @ORM\Index(name="ec_esc_oa_io_idx", columns={"event_category", "event_sub_category", "is_open"})
  17. * }
  18. * )
  19. */
  20. class CircuitbreakerEvent
  21. {
  22. /**
  23. * @var string
  24. *
  25. * @ORM\GeneratedValue(strategy="CUSTOM")
  26. *
  27. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  28. *
  29. * @ORM\Column(name="id", type="guid")
  30. *
  31. * @ORM\Id
  32. */
  33. protected $id;
  34. /**
  35. * @var int
  36. *
  37. * @ORM\Column(name="event_category", type="smallint", nullable=false)
  38. */
  39. protected $eventCategory;
  40. /**
  41. * @var string|null
  42. *
  43. * @ORM\Column(name="event_sub_category", type="string", length=128, nullable=true)
  44. */
  45. protected $eventSubCategory;
  46. /**
  47. * @var DateTime
  48. *
  49. * @ORM\Column(name="occured_at", type="datetime", nullable=false)
  50. */
  51. protected $occuredAt;
  52. /**
  53. * @var bool
  54. *
  55. * @ORM\Column(name="is_open", type="boolean", nullable=false)
  56. */
  57. protected $isOpen;
  58. public function getId(): string
  59. {
  60. return $this->id;
  61. }
  62. public function getEventCategory(): int
  63. {
  64. return $this->eventCategory;
  65. }
  66. /**
  67. * @throws Exception
  68. */
  69. public function getEventCategoryTitle(): string
  70. {
  71. $refl = new ReflectionClass(CircuitbreakerService::class);
  72. $constants = $refl->getConstants();
  73. foreach ($constants as $constantName => $constantValue) {
  74. if (substr($constantName, 0, 15) === 'EVENT_CATEGORY_' && $constantValue === $this->getEventCategory()) {
  75. return strtolower(str_replace('_', '-', substr($constantName, 15)));
  76. }
  77. }
  78. throw new Exception('Cannot resolve title for event category ' . $this->getEventCategory());
  79. }
  80. public function setEventCategory(int $eventCategory): void
  81. {
  82. $this->eventCategory = $eventCategory;
  83. }
  84. public function getEventSubCategory(): string
  85. {
  86. return $this->eventSubCategory;
  87. }
  88. public function setEventSubCategory(string $eventSubCategory): void
  89. {
  90. $this->eventSubCategory = $eventSubCategory;
  91. }
  92. public function getOccuredAt(): DateTime
  93. {
  94. return $this->occuredAt;
  95. }
  96. public function setOccuredAt(DateTime $occuredAt): void
  97. {
  98. $this->occuredAt = $occuredAt;
  99. }
  100. public function isOpen(): bool
  101. {
  102. return $this->isOpen;
  103. }
  104. public function setIsOpen(bool $isOpen): void
  105. {
  106. $this->isOpen = $isOpen;
  107. }
  108. }