PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.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 / EndpointV2 / EndpointProviderV2.php

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

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