ErrorRule.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Aws\EndpointV2\Rule;
  3. use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
  4. use Aws\Exception\UnresolvedEndpointException;
  5. class ErrorRule extends AbstractRule
  6. {
  7. /** @var array */
  8. private $error;
  9. public function __construct($definition)
  10. {
  11. parent::__construct($definition);
  12. $this->error = $definition['error'];
  13. }
  14. /**
  15. * @return array
  16. */
  17. public function getError()
  18. {
  19. return $this->error;
  20. }
  21. /**
  22. * If an error rule's conditions are met, raise an
  23. * UnresolvedEndpointError containing the fully resolved error string.
  24. *
  25. * @return null
  26. * @throws UnresolvedEndpointException
  27. */
  28. public function evaluate(
  29. array $inputParameters,
  30. RulesetStandardLibrary $standardLibrary
  31. )
  32. {
  33. if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
  34. $message = $standardLibrary->resolveValue($this->error, $inputParameters);
  35. throw new UnresolvedEndpointException($message);
  36. }
  37. return false;
  38. }
  39. }