Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Aws\EndpointV2;
4
 
5
use Aws\Api\Serializer\RestSerializer;
1441 ariadna 6
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
1 efrain 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
    /**
1441 ariadna 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.
1 efrain 20
     *
1441 ariadna 21
     * @param $endpoint
22
     * @param $headers
23
     *
24
     * @return void
1 efrain 25
     */
1441 ariadna 26
    private function setEndpointV2RequestOptions(
27
        RulesetEndpoint $endpoint,
28
        array &$headers
29
    ): void
1 efrain 30
    {
1441 ariadna 31
        $this->applyHeaders($endpoint, $headers);
1 efrain 32
        $resolvedUrl = $endpoint->getUrl();
33
        $this->applyScheme($resolvedUrl);
1441 ariadna 34
        $this->endpoint = $this instanceof RestSerializer
35
            ? new Uri($resolvedUrl)
36
            : $resolvedUrl;
1 efrain 37
    }
38
 
39
    /**
1441 ariadna 40
     * Combines modeled headers and headers resolved from an endpoint object.
41
     *
42
     * @param $endpoint
43
     * @param $headers
44
     * @return void
1 efrain 45
     */
1441 ariadna 46
    private function applyHeaders(RulesetEndpoint $endpoint, array &$headers): void
1 efrain 47
    {
48
        if (!is_null($endpoint->getHeaders())) {
49
           $headers = array_merge(
50
               $headers,
51
               $endpoint->getHeaders()
52
           );
53
        }
54
    }
55
 
1441 ariadna 56
    /**
57
     * Applies custom HTTP schemes provided in client configuration.
58
     *
59
     * @param $resolvedUrl
60
     * @return void
61
     */
62
    private function applyScheme(&$resolvedUrl): void
1 efrain 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
}