Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Endpoint/PatternEndpointProvider.php

raw symbols SCIP
1 <?php
2 namespace Aws\Endpoint;
3
4 /**
5 * Provides endpoints based on an endpoint pattern configuration array.
6 */
7 class PatternEndpointProvider
8 {
9 /** @var array */
10 private $patterns;
11
12 /**
13 * @param array $patterns Hash of endpoint patterns mapping to endpoint
14 * configurations.
15 */
16 public function __construct(array $patterns)
17 {
18 $this->patterns = $patterns;
19 }
20
21 public function __invoke(array $args = [])
22 {
23 $service = isset($args['service']) ? $args['service'] : '';
24 $region = isset($args['region']) ? $args['region'] : '';
25 $keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"];
26
27 foreach ($keys as $key) {
28 if (isset($this->patterns[$key])) {
29 return $this->expand(
30 $this->patterns[$key],
31 isset($args['scheme']) ? $args['scheme'] : 'https',
32 $service,
33 $region
34 );
35 }
36 }
37
38 return null;
39 }
40
41 private function expand(array $config, $scheme, $service, $region)
42 {
43 $config['endpoint'] = $scheme . '://'
44 . strtr($config['endpoint'], [
45 '{service}' => $service,
46 '{region}' => $region
47 ]);
48
49 return $config;
50 }
51 }