1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Resolver; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class VersionResolver |
9
|
|
|
* |
10
|
|
|
* @internal |
11
|
|
|
* @internal |
12
|
|
|
* @codeCoverageIgnore |
13
|
|
|
* @package AlibabaCloud\Client\Resolver |
14
|
|
|
*/ |
15
|
|
|
abstract class VersionResolver |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $name |
20
|
|
|
* @param array $arguments |
21
|
|
|
* |
22
|
|
|
* @return mixed |
23
|
|
|
*/ |
24
|
|
|
public static function __callStatic($name, $arguments) |
25
|
|
|
{ |
26
|
|
|
return (new static())->__call($name, $arguments); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $version |
31
|
|
|
* @param array $arguments |
32
|
|
|
* |
33
|
|
|
* @return mixed |
34
|
|
|
* @throws ClientException |
35
|
|
|
*/ |
36
|
|
|
public function __call($version, $arguments) |
37
|
|
|
{ |
38
|
|
|
$version = \ucfirst($version); |
39
|
|
|
$product = $this->getProductName(); |
40
|
|
|
|
41
|
|
|
$position = strpos($product, 'Version'); |
42
|
|
|
if ($position !== false && $position !== 0) { |
43
|
|
|
$product = \str_replace('Version', '', $product); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$class = "AlibabaCloud\\{$product}\\$version\\{$product}ApiResolver"; |
47
|
|
|
|
48
|
|
|
if (\class_exists($class)) { |
49
|
|
|
return new $class(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
throw new ClientException( |
53
|
|
|
"$product Versions contains no {$version}", |
54
|
|
|
'SDK.VersionNotFound' |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return mixed |
60
|
|
|
* @throws ClientException |
61
|
|
|
*/ |
62
|
|
|
private function getProductName() |
63
|
|
|
{ |
64
|
|
|
$array = \explode('\\', \get_class($this)); |
65
|
|
|
|
66
|
|
|
if (isset($array[1])) { |
67
|
|
|
return $array[1]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
throw new ClientException( |
71
|
|
|
'Service name not found.', |
72
|
|
|
'SDK.ServiceNotFound' |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|