|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Regions; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class EndpointUserConfig |
|
7
|
|
|
* |
|
8
|
|
|
* @package AlibabaCloud\Client\Regions |
|
9
|
|
|
*/ |
|
10
|
|
|
class EndpointUserConfig |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var array user customized EndpointData |
|
14
|
|
|
*/ |
|
15
|
|
|
private static $hosts = []; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Add host based on product name and region. |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $product |
|
21
|
|
|
* @param string $regionId |
|
22
|
|
|
* @param string $host |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function addHost($product, $regionId, $host) |
|
25
|
|
|
{ |
|
26
|
|
|
if (empty($product) || empty($regionId) || empty($host)) { |
|
27
|
|
|
return; |
|
28
|
|
|
} |
|
29
|
|
|
$key = self::key($product, $regionId); |
|
30
|
|
|
|
|
31
|
|
|
self::$hosts[$key] = $host; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get host based on product name and region. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $product |
|
38
|
|
|
* @param string $regionId |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function getHost($product, $regionId) |
|
43
|
|
|
{ |
|
44
|
|
|
$key = self::key($product, $regionId); |
|
45
|
|
|
return isset(self::$hosts[$key]) ? self::$hosts[$key] : ""; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Delete host based on product name and region. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $product |
|
52
|
|
|
* @param string $regionId |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function deleteHost($product, $regionId) |
|
55
|
|
|
{ |
|
56
|
|
|
$key = self::key($product, $regionId); |
|
57
|
|
|
if (isset(self::$hosts[$key])) { |
|
58
|
|
|
unset(self::$hosts[$key]); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $product |
|
64
|
|
|
* @param string $regionId |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private static function key($product, $regionId) |
|
69
|
|
|
{ |
|
70
|
|
|
if (empty($product) || empty($regionId)) { |
|
71
|
|
|
throw new \InvalidArgumentException('InvalidArgument : $product or $regionId is empty'); |
|
72
|
|
|
} |
|
73
|
|
|
return $product . "_" . $regionId; |
|
74
|
|
|
} |
|
75
|
|
|
} |