Rule
11 months ago
Ruleset
11 months ago
EndpointDefinitionProvider.php
11 months ago
EndpointProviderV2.php
11 months ago
EndpointV2Middleware.php
11 months ago
EndpointV2SerializerTrait.php
11 months ago
EndpointV2SerializerTrait.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Aws\EndpointV2; |
| 4 | |
| 5 | use Aws\Api\Serializer\RestSerializer; |
| 6 | use Aws\EndpointV2\Ruleset\RulesetEndpoint; |
| 7 | use GuzzleHttp\Psr7\Uri; |
| 8 | |
| 9 | /** |
| 10 | * Set of helper functions used to set endpoints and endpoint |
| 11 | * properties derived from dynamic endpoint resolution. |
| 12 | * |
| 13 | * @internal |
| 14 | */ |
| 15 | trait EndpointV2SerializerTrait |
| 16 | { |
| 17 | /** |
| 18 | * Applies a resolved endpoint, headers and any custom HTTP schemes provided |
| 19 | * in client configuration to options which are applied to the serialized request. |
| 20 | * |
| 21 | * @param $endpoint |
| 22 | * @param $headers |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | private function setEndpointV2RequestOptions( |
| 27 | RulesetEndpoint $endpoint, |
| 28 | array &$headers |
| 29 | ): void |
| 30 | { |
| 31 | $this->applyHeaders($endpoint, $headers); |
| 32 | $resolvedUrl = $endpoint->getUrl(); |
| 33 | $this->applyScheme($resolvedUrl); |
| 34 | $this->endpoint = $this instanceof RestSerializer |
| 35 | ? new Uri($resolvedUrl) |
| 36 | : $resolvedUrl; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Combines modeled headers and headers resolved from an endpoint object. |
| 41 | * |
| 42 | * @param $endpoint |
| 43 | * @param $headers |
| 44 | * @return void |
| 45 | */ |
| 46 | private function applyHeaders(RulesetEndpoint $endpoint, array &$headers): void |
| 47 | { |
| 48 | if (!is_null($endpoint->getHeaders())) { |
| 49 | $headers = array_merge( |
| 50 | $headers, |
| 51 | $endpoint->getHeaders() |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Applies custom HTTP schemes provided in client configuration. |
| 58 | * |
| 59 | * @param $resolvedUrl |
| 60 | * @return void |
| 61 | */ |
| 62 | private function applyScheme(&$resolvedUrl): void |
| 63 | { |
| 64 | $resolvedEndpointScheme = parse_url($resolvedUrl, PHP_URL_SCHEME); |
| 65 | $scheme = $this->endpoint instanceof Uri |
| 66 | ? $this->endpoint->getScheme() |
| 67 | : parse_url($this->endpoint, PHP_URL_SCHEME); |
| 68 | |
| 69 | if (!empty($scheme) && $scheme !== $resolvedEndpointScheme) { |
| 70 | $resolvedUrl = str_replace( |
| 71 | $resolvedEndpointScheme, |
| 72 | $scheme, |
| 73 | $resolvedUrl |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 |