PluginProbe
Media Cloud Sync / 1.1.1
Media Cloud Sync v1.1.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Endpoint / PatternEndpointProvider.php

PatternEndpointProvider.php in Media Cloud Sync 1.1.1, at includes/sdk/s3/Aws/Endpoint/PatternEndpointProvider.php

38 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Endpoint;
4
5 /**
6 * Provides endpoints based on an endpoint pattern configuration array.
7 */
8 class PatternEndpointProvider
9 {
10 /** @var array */
11 private $patterns;
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 public function __invoke(array $args = [])
21 {
22 $service = isset($args['service']) ? $args['service'] : '';
23 $region = isset($args['region']) ? $args['region'] : '';
24 $keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"];
25 foreach ($keys as $key) {
26 if (isset($this->patterns[$key])) {
27 return $this->expand($this->patterns[$key], isset($args['scheme']) ? $args['scheme'] : 'https', $service, $region);
28 }
29 }
30 return null;
31 }
32 private function expand(array $config, $scheme, $service, $region)
33 {
34 $config['endpoint'] = $scheme . '://' . \strtr($config['endpoint'], ['{service}' => $service, '{region}' => $region]);
35 return $config;
36 }
37 }
38