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