| 1 |
<?php |
| 2 |
|
| 3 |
namespace Aws\EndpointV2\Rule; |
| 4 |
|
| 5 |
use Aws\EndpointV2\Ruleset\RulesetStandardLibrary; |
| 6 |
use Aws\EndpointV2\Ruleset\RulesetEndpoint; |
| 7 |
|
| 8 |
class EndpointRule extends AbstractRule |
| 9 |
{ |
| 10 |
|
| 11 |
private $endpoint; |
| 12 |
|
| 13 |
public function __construct(array $definition) |
| 14 |
{ |
| 15 |
parent::__construct($definition); |
| 16 |
$this->endpoint = $definition['endpoint']; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function getEndpoint() |
| 23 |
{ |
| 24 |
return $this->endpoint; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary) |
| 34 |
{ |
| 35 |
if ($this->evaluateConditions($inputParameters, $standardLibrary)) { |
| 36 |
return $this->resolve($inputParameters, $standardLibrary); |
| 37 |
} |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
private function resolve( |
| 47 |
array $inputParameters, |
| 48 |
RulesetStandardLibrary $standardLibrary |
| 49 |
) |
| 50 |
{ |
| 51 |
$uri = $standardLibrary->resolveValue($this->endpoint['url'], $inputParameters); |
| 52 |
$properties = isset($this->endpoint['properties']) |
| 53 |
? $this->resolveProperties($this->endpoint['properties'], $inputParameters, $standardLibrary) |
| 54 |
: null; |
| 55 |
$headers = $this->resolveHeaders($inputParameters, $standardLibrary); |
| 56 |
|
| 57 |
return new RulesetEndpoint($uri, $properties, $headers); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
private function resolveProperties( |
| 67 |
$properties, |
| 68 |
array $inputParameters, |
| 69 |
RulesetStandardLibrary $standardLibrary |
| 70 |
) |
| 71 |
{ |
| 72 |
if (is_array($properties)) { |
| 73 |
$propertiesArr = []; |
| 74 |
foreach($properties as $key => $val) { |
| 75 |
$propertiesArr[$key] = $this->resolveProperties($val, $inputParameters, $standardLibrary); |
| 76 |
} |
| 77 |
return $propertiesArr; |
| 78 |
} elseif ($standardLibrary->isTemplate($properties)) { |
| 79 |
return $standardLibrary->resolveTemplateString($properties, $inputParameters); |
| 80 |
} |
| 81 |
return $properties; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
private function resolveHeaders( |
| 91 |
array $inputParameters, |
| 92 |
RulesetStandardLibrary $standardLibrary |
| 93 |
) |
| 94 |
{ |
| 95 |
$headers = isset($this->endpoint['headers']) ? $this->endpoint['headers'] : null; |
| 96 |
if (is_null($headers)) { |
| 97 |
return null; |
| 98 |
} |
| 99 |
$resolvedHeaders = []; |
| 100 |
|
| 101 |
foreach($headers as $headerName => $headerValues) { |
| 102 |
$resolvedValues = []; |
| 103 |
foreach($headerValues as $value) { |
| 104 |
$resolvedValue = $standardLibrary->resolveValue($value, $inputParameters, $standardLibrary); |
| 105 |
$resolvedValues[] = $resolvedValue; |
| 106 |
} |
| 107 |
$resolvedHeaders[$headerName] = $resolvedValues; |
| 108 |
} |
| 109 |
return $resolvedHeaders; |
| 110 |
} |
| 111 |
} |