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