Problem.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace Grav\Plugin\Problems\Base;
  3. use JsonSerializable;
  4. /**
  5. * Class Problem
  6. * @package Grav\Plugin\Problems\Base
  7. */
  8. class Problem implements JsonSerializable
  9. {
  10. const LEVEL_CRITICAL = 'critical';
  11. const LEVEL_WARNING = 'warning';
  12. const LEVEL_NOTICE = 'notice';
  13. /** @var string */
  14. protected $id = '';
  15. /** @var int */
  16. protected $order = 0;
  17. /** @var string */
  18. protected $level = '';
  19. /** @var bool */
  20. protected $status = false;
  21. /** @var string */
  22. protected $msg = '';
  23. /** @var array */
  24. protected $details = [];
  25. /** @var string */
  26. protected $help = '';
  27. /** @var string */
  28. protected $class = '';
  29. /**
  30. * @param array $data
  31. * @return void
  32. */
  33. public function load(array $data): void
  34. {
  35. $this->set_object_vars($data);
  36. }
  37. /**
  38. * @return $this
  39. */
  40. public function process()
  41. {
  42. return $this;
  43. }
  44. /**
  45. * @return string
  46. */
  47. public function getId(): string
  48. {
  49. return $this->id;
  50. }
  51. /**
  52. * @return int
  53. */
  54. public function getOrder(): int
  55. {
  56. return $this->order;
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function getLevel(): string
  62. {
  63. return $this->level;
  64. }
  65. /**
  66. * @return bool
  67. */
  68. public function getStatus(): bool
  69. {
  70. return $this->status;
  71. }
  72. /**
  73. * @return string
  74. */
  75. public function getMsg(): string
  76. {
  77. return $this->msg;
  78. }
  79. /**
  80. * @return array
  81. */
  82. public function getDetails(): array
  83. {
  84. return $this->details;
  85. }
  86. /**
  87. * @return string
  88. */
  89. public function getHelp(): string
  90. {
  91. return $this->help;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function getClass(): string
  97. {
  98. return $this->class;
  99. }
  100. /**
  101. * @return array
  102. */
  103. public function toArray(): array
  104. {
  105. return get_object_vars($this);
  106. }
  107. /**
  108. * @return array
  109. */
  110. public function jsonSerialize(): array
  111. {
  112. return $this->toArray();
  113. }
  114. /**
  115. * @param array $vars
  116. */
  117. protected function set_object_vars(array $vars): void
  118. {
  119. $has = get_object_vars($this);
  120. foreach ($has as $name => $oldValue) {
  121. $this->{$name} = $vars[$name] ?? null;
  122. }
  123. }
  124. }