PluginProbe
Media Cloud Sync / 1.2.13
Media Cloud Sync v1.2.13
1.4.2 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 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / EndpointV2 / EndpointProviderV2.php

EndpointProviderV2.php in Media Cloud Sync 1.2.13, at includes/sdk/s3/Aws/EndpointV2/EndpointProviderV2.php

57 lines 1.7 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\EndpointV2;
4
5 use Dudlewebs\WPMCS\s3\Aws\EndpointV2\Ruleset\Ruleset;
6 use Dudlewebs\WPMCS\s3\Aws\Exception\UnresolvedEndpointException;
7 use Dudlewebs\WPMCS\s3\Aws\LruArrayCache;
8 /**
9 * Given a service's Ruleset and client-provided input parameters, provides
10 * either an object reflecting the properties of a resolved endpoint,
11 * or throws an error.
12 */
13 class EndpointProviderV2
14 {
15 /** @var Ruleset */
16 private $ruleset;
17 /** @var LruArrayCache */
18 private $cache;
19 public function __construct(array $ruleset, array $partitions)
20 {
21 $this->ruleset = new Ruleset($ruleset, $partitions);
22 $this->cache = new LruArrayCache(100);
23 }
24 /**
25 * @return Ruleset
26 */
27 public function getRuleset()
28 {
29 return $this->ruleset;
30 }
31 /**
32 * Given a Ruleset and input parameters, determines the correct endpoint
33 * or an error to be thrown for a given request.
34 *
35 * @return RulesetEndpoint
36 * @throws UnresolvedEndpointException
37 */
38 public function resolveEndpoint(array $inputParameters)
39 {
40 $hashedParams = $this->hashInputParameters($inputParameters);
41 $match = $this->cache->get($hashedParams);
42 if (!\is_null($match)) {
43 return $match;
44 }
45 $endpoint = $this->ruleset->evaluate($inputParameters);
46 if ($endpoint === \false) {
47 throw new UnresolvedEndpointException('Unable to resolve an endpoint using the provider arguments: ' . \json_encode($inputParameters));
48 }
49 $this->cache->set($hashedParams, $endpoint);
50 return $endpoint;
51 }
52 private function hashInputParameters($inputParameters)
53 {
54 return \md5(\serialize($inputParameters));
55 }
56 }
57