AbstractRule.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Aws\EndpointV2\Rule;
  3. use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
  4. /**
  5. * A rule within a rule set. All rules contain a conditions property,
  6. * which can be empty, and documentation about the rule.
  7. */
  8. abstract class AbstractRule
  9. {
  10. private $conditions;
  11. private $documentation;
  12. public function __construct(array $definition)
  13. {
  14. $this->conditions = $definition['conditions'];
  15. $this->documentation = isset($definition['documentation']) ?
  16. $definition['documentation'] : null;
  17. }
  18. /**
  19. * @return array
  20. */
  21. public function getConditions()
  22. {
  23. return $this->conditions;
  24. }
  25. /**
  26. * @return mixed
  27. */
  28. public function getDocumentation()
  29. {
  30. return $this->documentation;
  31. }
  32. /**
  33. * Determines if all conditions for a given rule are met.
  34. *
  35. * @return boolean
  36. */
  37. protected function evaluateConditions(
  38. array &$inputParameters,
  39. RulesetStandardLibrary $standardLibrary
  40. )
  41. {
  42. foreach($this->getConditions() as $condition) {
  43. $result = $standardLibrary->callFunction($condition, $inputParameters);
  44. if (is_null($result) || $result === false) {
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. abstract public function evaluate(
  51. array $inputParameters,
  52. RulesetStandardLibrary $standardLibrary
  53. );
  54. }