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 / EndpointDefinitionProvider.php

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

58 lines 2.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\EndpointV2;
4
5 /**
6 * Provides Endpoint-related artifacts used for endpoint resolution
7 * and testing.
8 */
9 class EndpointDefinitionProvider
10 {
11 public static function getEndpointRuleset($service, $apiVersion, $baseDir = null)
12 {
13 return self::getData($service, $apiVersion, 'ruleset', $baseDir);
14 }
15 public static function getEndpointTests($service, $apiVersion, $baseDir = null)
16 {
17 return self::getData($service, $apiVersion, 'tests', $baseDir);
18 }
19 public static function getPartitions()
20 {
21 $basePath = __DIR__ . '/../data';
22 $file = '/partitions.json';
23 if (\file_exists($basePath . $file . '.php')) {
24 return require $basePath . $file . '.php';
25 } else {
26 return \json_decode(\file_get_contents($basePath . $file));
27 }
28 }
29 private static function getData($service, $apiVersion, $type, $baseDir)
30 {
31 $basePath = $baseDir ? $baseDir : __DIR__ . '/../data';
32 $serviceDir = $basePath . "/{$service}";
33 if (!\is_dir($serviceDir)) {
34 throw new \InvalidArgumentException('Invalid service name.');
35 }
36 if ($apiVersion === 'latest') {
37 $apiVersion = self::getLatest($service);
38 }
39 $rulesetPath = $serviceDir . '/' . $apiVersion;
40 if (!\is_dir($rulesetPath)) {
41 throw new \InvalidArgumentException('Invalid api version.');
42 }
43 $fileName = $type === 'tests' ? '/endpoint-tests-1' : '/endpoint-rule-set-1';
44 if (\file_exists($rulesetPath . $fileName . '.json.php')) {
45 return require $rulesetPath . $fileName . '.json.php';
46 } elseif (\file_exists($rulesetPath . $fileName . '.json')) {
47 return \json_decode(\file_get_contents($rulesetPath . $fileName . '.json'), \true);
48 } else {
49 throw new \InvalidArgumentException('Specified ' . $type . ' endpoint file for ' . $service . ' with api version ' . $apiVersion . ' does not exist.');
50 }
51 }
52 private static function getLatest($service)
53 {
54 $manifest = \Dudlewebs\WPMCS\s3\Aws\manifest();
55 return $manifest[$service]['versions']['latest'];
56 }
57 }
58