Restriction.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Libs\Restrictions;
  3. use ThurData\Servers\KerioEmail\App\Libs\Restrictions\Interfaces\AbstractRestriction;
  4. use ThurData\Servers\KerioEmail\App\Libs\Restrictions\Interfaces\RuleInterface;
  5. /**
  6. *
  7. * Created by PhpStorm.
  8. * User: Tomasz Bielecki ( tomasz.bi@thurdata.com )
  9. * Date: 07.11.19
  10. * Time: 09:58
  11. * Class Restriction
  12. */
  13. class Restriction extends AbstractRestriction
  14. {
  15. /**
  16. * {@inheritDoc}
  17. */
  18. public function check()
  19. {
  20. /**
  21. *
  22. * check if rule is valid
  23. */
  24. if($this->rule->isValid() !== false)
  25. {
  26. return true;
  27. }
  28. /**
  29. * set status as invalid
  30. */
  31. $this->setIsValid(self::STATUS_INVALID);
  32. /**
  33. *
  34. * set error message
  35. */
  36. $this->setErrorMessage($this->rule->getMessage());
  37. /**
  38. *
  39. * throw error if is enabled
  40. */
  41. if($this->isThrowErrorEnabled())
  42. {
  43. throw new \Exception($this->getErrorMessage());
  44. }
  45. /**
  46. *
  47. * return valid status
  48. */
  49. return $this->isValid();
  50. }
  51. }