summaryrefslogtreecommitdiff
path: root/vendor/aws/aws-sdk-php/src/EndpointV2/Rule
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/aws/aws-sdk-php/src/EndpointV2/Rule')
-rw-r--r--vendor/aws/aws-sdk-php/src/EndpointV2/Rule/AbstractRule.php62
-rw-r--r--vendor/aws/aws-sdk-php/src/EndpointV2/Rule/EndpointRule.php111
-rw-r--r--vendor/aws/aws-sdk-php/src/EndpointV2/Rule/ErrorRule.php45
-rw-r--r--vendor/aws/aws-sdk-php/src/EndpointV2/Rule/RuleCreator.php26
-rw-r--r--vendor/aws/aws-sdk-php/src/EndpointV2/Rule/TreeRule.php61
5 files changed, 305 insertions, 0 deletions
diff --git a/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/AbstractRule.php b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/AbstractRule.php
new file mode 100644
index 0000000..94da12d
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/AbstractRule.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Aws\EndpointV2\Rule;
+
+use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
+
+/**
+ * A rule within a rule set. All rules contain a conditions property,
+ * which can be empty, and documentation about the rule.
+ */
+abstract Class AbstractRule
+{
+ private $conditions;
+ private $documentation;
+
+ public function __construct(array $definition)
+ {
+ $this->conditions = $definition['conditions'];
+ $this->documentation = isset($definition['documentation']) ?
+ $definition['documentation'] : null;
+ }
+
+ /**
+ * @return array
+ */
+ public function getConditions()
+ {
+ return $this->conditions;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getDocumentation()
+ {
+ return $this->documentation;
+ }
+
+ /**
+ * Determines if all conditions for a given rule are met.
+ *
+ * @return boolean
+ */
+ protected function evaluateConditions(
+ array &$inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ foreach($this->getConditions() as $condition) {
+ $result = $standardLibrary->callFunction($condition, $inputParameters);
+ if (is_null($result) || $result === false) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ abstract public function evaluate(
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ );
+}
diff --git a/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/EndpointRule.php b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/EndpointRule.php
new file mode 100644
index 0000000..b6b276d
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/EndpointRule.php
@@ -0,0 +1,111 @@
+<?php
+
+namespace Aws\EndpointV2\Rule;
+
+use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
+use Aws\EndpointV2\Ruleset\RulesetEndpoint;
+
+Class EndpointRule extends AbstractRule
+{
+ /** @var array */
+ private $endpoint;
+
+ public function __construct(array $definition)
+ {
+ parent::__construct($definition);
+ $this->endpoint = $definition['endpoint'];
+ }
+
+ /**
+ * @return array
+ */
+ public function getEndpoint()
+ {
+ return $this->endpoint;
+ }
+
+ /**
+ * If all the rule's conditions are met, return the resolved
+ * endpoint object.
+ *
+ * @return RulesetEndpoint | null
+ */
+ public function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary)
+ {
+ if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
+ return $this->resolve($inputParameters, $standardLibrary);
+ }
+ return false;
+ }
+
+ /**
+ * Given input parameters, resolve an endpoint in its entirety.
+ *
+ * @return RulesetEndpoint
+ */
+ private function resolve(
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ $uri = $standardLibrary->resolveValue($this->endpoint['url'], $inputParameters);
+ $properties = isset($this->endpoint['properties'])
+ ? $this->resolveProperties($this->endpoint['properties'], $inputParameters, $standardLibrary)
+ : null;
+ $headers = $this->resolveHeaders($inputParameters, $standardLibrary);
+
+ return new RulesetEndpoint($uri, $properties, $headers);
+ }
+
+ /**
+ * Recurse through an endpoint's `properties` attribute, resolving template
+ * strings when found. Return the fully resolved attribute.
+ *
+ * @return array
+ */
+ private function resolveProperties(
+ $properties,
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ if (is_array($properties)) {
+ $propertiesArr = [];
+ foreach($properties as $key => $val) {
+ $propertiesArr[$key] = $this->resolveProperties($val, $inputParameters, $standardLibrary);
+ }
+ return $propertiesArr;
+ } elseif ($standardLibrary->isTemplate($properties)) {
+ return $standardLibrary->resolveTemplateString($properties, $inputParameters);
+ }
+ return $properties;
+ }
+
+ /**
+ * If present, iterate through an endpoint's headers attribute resolving
+ * values along the way. Return the fully resolved attribute.
+ *
+ * @return array
+ */
+ private function resolveHeaders(
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ $headers = isset($this->endpoint['headers']) ? $this->endpoint['headers'] : null;
+ if (is_null($headers)) {
+ return null;
+ }
+ $resolvedHeaders = [];
+
+ foreach($headers as $headerName => $headerValues) {
+ $resolvedValues = [];
+ foreach($headerValues as $value) {
+ $resolvedValue = $standardLibrary->resolveValue($value, $inputParameters, $standardLibrary);
+ $resolvedValues[] = $resolvedValue;
+ }
+ $resolvedHeaders[$headerName] = $resolvedValues;
+ }
+ return $resolvedHeaders;
+ }
+}
diff --git a/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/ErrorRule.php b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/ErrorRule.php
new file mode 100644
index 0000000..941624a
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/ErrorRule.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Aws\EndpointV2\Rule;
+
+use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
+use Aws\Exception\UnresolvedEndpointException;
+
+class ErrorRule extends AbstractRule
+{
+ /** @var array */
+ private $error;
+
+ public function __construct($definition)
+ {
+ parent::__construct($definition);
+ $this->error = $definition['error'];
+ }
+
+ /**
+ * @return array
+ */
+ public function getError()
+ {
+ return $this->error;
+ }
+
+ /**
+ * If an error rule's conditions are met, raise an
+ * UnresolvedEndpointError containing the fully resolved error string.
+ *
+ * @return null
+ * @throws UnresolvedEndpointException
+ */
+ public function evaluate(
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
+ $message = $standardLibrary->resolveValue($this->error, $inputParameters);
+ throw new UnresolvedEndpointException($message);
+ }
+ return false;
+ }
+}
diff --git a/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/RuleCreator.php b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/RuleCreator.php
new file mode 100644
index 0000000..279477e
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/RuleCreator.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Aws\EndpointV2\Rule;
+
+use Aws\Exception\UnresolvedEndpointException;
+
+class RuleCreator
+{
+ public static function create($type, $definition)
+ {
+ switch ($type) {
+ case 'endpoint':
+ return new EndpointRule($definition);
+ case 'error':
+ return new ErrorRule($definition);
+ case 'tree':
+ return new TreeRule($definition);
+ default:
+ throw new UnresolvedEndpointException(
+ 'Unknown rule type ' . $type .
+ ' must be of type `endpoint`, `tree` or `error`'
+ );
+ }
+ }
+}
+
diff --git a/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/TreeRule.php b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/TreeRule.php
new file mode 100644
index 0000000..aa98180
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/EndpointV2/Rule/TreeRule.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Aws\EndpointV2\Rule;
+
+use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
+
+class TreeRule extends AbstractRule
+{
+ /** @var array */
+ private $rules;
+
+ public function __construct(array $definition)
+ {
+ parent::__construct($definition);
+ $this->rules = $this->createRules($definition['rules']);
+ }
+
+ /**
+ * @return array
+ */
+ public function getRules()
+ {
+ return $this->rules;
+ }
+
+ /**
+ * If a tree rule's conditions evaluate successfully, iterate over its
+ * subordinate rules and return a result if there is one. If any of the
+ * subsequent rules are trees, the function will recurse until it reaches
+ * an error or an endpoint rule
+ *
+ * @return mixed
+ */
+ public function evaluate(
+ array $inputParameters,
+ RulesetStandardLibrary $standardLibrary
+ )
+ {
+ if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
+ foreach($this->rules as $rule) {
+ $inputParametersCopy = $inputParameters;
+ $evaluation = $rule->evaluate($inputParametersCopy, $standardLibrary);
+ if ($evaluation !== false) {
+ return $evaluation;
+ }
+ }
+ }
+ return false;
+ }
+
+ private function createRules(array $rules)
+ {
+ $rulesList = [];
+
+ forEach($rules as $rule) {
+ $ruleType = RuleCreator::create($rule['type'], $rule);
+ $rulesList[] = $ruleType;
+ }
+ return $rulesList;
+ }
+}