AbstractRestriction.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Libs\Restrictions\Interfaces;
  3. use ThurData\Servers\KerioEmail\App\Libs\Restrictions\Restriction;
  4. /**
  5. *
  6. * Created by PhpStorm.
  7. * User: Tomasz Bielecki ( tomasz.bi@thurdata.com )
  8. * Date: 07.11.19
  9. * Time: 10:29
  10. * Class AbstractRestriction
  11. */
  12. abstract class AbstractRestriction
  13. {
  14. const STATUS_VALID = true;
  15. const STATUS_INVALID = false;
  16. /**
  17. * @var bool
  18. */
  19. protected $throwError = false;
  20. /**
  21. * @var RuleInterface
  22. */
  23. protected $rule;
  24. /**
  25. * @var
  26. */
  27. public $errorMessage;
  28. /**
  29. * @var bool
  30. */
  31. public $isValid = self::STATUS_VALID;
  32. /**
  33. * Restriction constructor.
  34. * @param RuleInterface $rule
  35. */
  36. public function __construct(RuleInterface $rule)
  37. {
  38. $this->rule = $rule;
  39. }
  40. /**
  41. *
  42. * check restriction
  43. * @return mixed
  44. */
  45. public abstract function check();
  46. /**
  47. * @return bool
  48. */
  49. public function isThrowErrorEnabled()
  50. {
  51. return $this->throwError === true;
  52. }
  53. /**
  54. * @return $this
  55. */
  56. public function enableThrowError()
  57. {
  58. $this->throwError = true;
  59. return $this;
  60. }
  61. /**
  62. * @return $this
  63. */
  64. public function disableThrowError()
  65. {
  66. $this->throwError = true;
  67. return $this;
  68. }
  69. /**
  70. * @return RuleInterface
  71. */
  72. public function getRule()
  73. {
  74. return $this->rule;
  75. }
  76. /**
  77. * @param RuleInterface $rule
  78. */
  79. public function setRule(RuleInterface $rule)
  80. {
  81. $this->rule = $rule;
  82. }
  83. /**
  84. * @return mixed
  85. */
  86. public function getErrorMessage()
  87. {
  88. return $this->errorMessage;
  89. }
  90. /**
  91. * @param mixed $errorMessage
  92. */
  93. public function setErrorMessage($errorMessage)
  94. {
  95. $this->errorMessage = $errorMessage;
  96. }
  97. /**
  98. * @return bool
  99. */
  100. public function isValid()
  101. {
  102. return $this->isValid;
  103. }
  104. /**
  105. * @param bool $isValid
  106. */
  107. public function setIsValid($isValid)
  108. {
  109. $this->isValid = $isValid;
  110. }
  111. }