初始化仓库
This commit is contained in:
50
vendor/alibabacloud/client/src/Resolver/ActionResolverTrait.php
vendored
Normal file
50
vendor/alibabacloud/client/src/Resolver/ActionResolverTrait.php
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @mixin Rpc
|
||||
* @mixin Roa
|
||||
* @mixin Request
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
trait ActionResolverTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Resolve Action name from class name
|
||||
*/
|
||||
private function resolveActionName()
|
||||
{
|
||||
if (!$this->action) {
|
||||
$array = explode('\\', get_class($this));
|
||||
$this->action = array_pop($array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append SDK version into User-Agent
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function appendSdkUA()
|
||||
{
|
||||
if (!(new ReflectionClass(AlibabaCloud::class))->hasMethod('appendUserAgent')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!class_exists('AlibabaCloud\Release')) {
|
||||
return;
|
||||
}
|
||||
|
||||
AlibabaCloud::appendUserAgent('SDK', \AlibabaCloud\Release::VERSION);
|
||||
}
|
||||
}
|
||||
113
vendor/alibabacloud/client/src/Resolver/ApiResolver.php
vendored
Normal file
113
vendor/alibabacloud/client/src/Resolver/ApiResolver.php
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use ReflectionObject;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class ApiResolver
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
abstract class ApiResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $arguments
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
return (new static())->__call($name, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $api
|
||||
* @param $arguments
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __call($api, $arguments)
|
||||
{
|
||||
$product_name = $this->getProductName();
|
||||
$class = $this->getNamespace() . '\\' . \ucfirst($api);
|
||||
|
||||
if (\class_exists($class)) {
|
||||
if (isset($arguments[0])) {
|
||||
return $this->warpEndpoint(new $class($arguments[0]));
|
||||
}
|
||||
|
||||
return $this->warpEndpoint(new $class());
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
"{$product_name} contains no $api",
|
||||
'SDK.ApiNotFound'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function warpEndpoint(Request $request)
|
||||
{
|
||||
$reflect = new ReflectionObject($request);
|
||||
$product_dir = dirname(dirname($reflect->getFileName()));
|
||||
$endpoints_json = "$product_dir/endpoints.json";
|
||||
if (file_exists($endpoints_json)) {
|
||||
$endpoints = json_decode(file_get_contents($endpoints_json), true);
|
||||
if (isset($endpoints['endpoint_map'])) {
|
||||
$request->endpointMap = $endpoints['endpoint_map'];
|
||||
}
|
||||
if (isset($endpoints['endpoint_regional'])) {
|
||||
$request->endpointRegional = $endpoints['endpoint_regional'];
|
||||
}
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function getProductName()
|
||||
{
|
||||
$array = \explode('\\', \get_class($this));
|
||||
if (isset($array[3])) {
|
||||
return str_replace('ApiResolver', '', $array[3]);
|
||||
}
|
||||
throw new ClientException(
|
||||
'Service name not found.',
|
||||
'SDK.ServiceNotFound'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function getNamespace()
|
||||
{
|
||||
$array = \explode('\\', \get_class($this));
|
||||
|
||||
if (!isset($array[3])) {
|
||||
throw new ClientException(
|
||||
'Get namespace error.',
|
||||
'SDK.ParseError'
|
||||
);
|
||||
}
|
||||
|
||||
unset($array[3]);
|
||||
|
||||
return \implode('\\', $array);
|
||||
}
|
||||
}
|
||||
66
vendor/alibabacloud/client/src/Resolver/CallTrait.php
vendored
Normal file
66
vendor/alibabacloud/client/src/Resolver/CallTrait.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Trait CallTrait
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
trait CallTrait
|
||||
{
|
||||
/**
|
||||
* Magic method for set or get request parameters.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $arguments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (strncmp($name, 'get', 3) === 0) {
|
||||
$parameter = \mb_strcut($name, 3);
|
||||
|
||||
return $this->__get($parameter);
|
||||
}
|
||||
|
||||
if (strncmp($name, 'with', 4) === 0) {
|
||||
$parameter = \mb_strcut($name, 4);
|
||||
|
||||
$value = $this->getCallArguments($name, $arguments);
|
||||
$this->data[$parameter] = $value;
|
||||
$this->parameterPosition()[$parameter] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (strncmp($name, 'set', 3) === 0) {
|
||||
$parameter = \mb_strcut($name, 3);
|
||||
$with_method = "with$parameter";
|
||||
|
||||
return $this->$with_method($this->getCallArguments($name, $arguments));
|
||||
}
|
||||
|
||||
throw new RuntimeException('Call to undefined method ' . __CLASS__ . '::' . $name . '()');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
* @param int $index
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCallArguments($name, array $arguments, $index = 0)
|
||||
{
|
||||
if (!isset($arguments[$index])) {
|
||||
throw new \InvalidArgumentException("Missing arguments to method $name");
|
||||
}
|
||||
|
||||
return $arguments[$index];
|
||||
}
|
||||
}
|
||||
43
vendor/alibabacloud/client/src/Resolver/Roa.php
vendored
Normal file
43
vendor/alibabacloud/client/src/Resolver/Roa.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Request\RoaRequest;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* Class Roa
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
abstract class Roa extends RoaRequest
|
||||
{
|
||||
use ActionResolverTrait;
|
||||
use CallTrait;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
$this->resolveActionName();
|
||||
$this->appendSdkUA();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function ¶meterPosition()
|
||||
{
|
||||
return $this->pathParameters;
|
||||
}
|
||||
}
|
||||
41
vendor/alibabacloud/client/src/Resolver/Rpc.php
vendored
Normal file
41
vendor/alibabacloud/client/src/Resolver/Rpc.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Request\RpcRequest;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* Class Rpc
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
abstract class Rpc extends RpcRequest
|
||||
{
|
||||
use ActionResolverTrait;
|
||||
use CallTrait;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
$this->resolveActionName();
|
||||
$this->appendSdkUA();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function ¶meterPosition()
|
||||
{
|
||||
return $this->options['query'];
|
||||
}
|
||||
}
|
||||
74
vendor/alibabacloud/client/src/Resolver/VersionResolver.php
vendored
Normal file
74
vendor/alibabacloud/client/src/Resolver/VersionResolver.php
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Resolver;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class VersionResolver
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client\Resolver
|
||||
*/
|
||||
abstract class VersionResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
return (new static())->__call($name, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __call($version, $arguments)
|
||||
{
|
||||
$version = \ucfirst($version);
|
||||
$product = $this->getProductName();
|
||||
|
||||
$position = strpos($product, 'Version');
|
||||
if ($position !== false && $position !== 0) {
|
||||
$product = \str_replace('Version', '', $product);
|
||||
}
|
||||
|
||||
$class = "AlibabaCloud\\{$product}\\$version\\{$product}ApiResolver";
|
||||
|
||||
if (\class_exists($class)) {
|
||||
return new $class();
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
"$product Versions contains no {$version}",
|
||||
'SDK.VersionNotFound'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function getProductName()
|
||||
{
|
||||
$array = \explode('\\', \get_class($this));
|
||||
|
||||
if (is_array($array) && isset($array[1])) {
|
||||
return $array[1];
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
'Service name not found.',
|
||||
'SDK.ServiceNotFound'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user