Commit 55038e5a authored by 谢宇轩's avatar 谢宇轩

Initial commit

parents
# This file is for unifying the coding style for different editors and IDEs.
# More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.bat]
end_of_line = crlf
[*.xml]
indent_style = space
indent_size = 4
[*.neon]
indent_style = tab
indent_size = 4
[*.{yaml,yml}]
indent_style = space
indent_size = 2
[composer.json]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
.idea/
.DS_STORE
.phpcs.cache
.phpunit.result.cache
composer.lock
Makefile
phpcs.xml
phpstan.neon
phpunit.xml
vendor/
\ No newline at end of file
<?php
// generated code, do not edit.
declare(strict_types=1);
namespace Jiwei\Test\SDK\Endpoint;
use Closure;
use Jiwei\EasyHttpSdk\Application;
use Jiwei\EasyHttpSdk\Exception\SdkException;
use Jiwei\EasyHttpSdk\Exception\ApplicationException;
use Jiwei\EasyHttpSdk\Exception\TimeOutExcetpion;
use Jiwei\EasyHttpSdk\Helper\ArgsRecorder;
use Jiwei\EasyHttpSdk\Helper\CallBackHelper;
use Jiwei\EasyHttpSdk\Http\SdkRequest;
class Test
{
use ArgsRecorder;
use CallBackHelper;
/** @var Application */
protected $application;
/**
* @param Application $application
*/
public function __construct(
Application $application
)
{
$this->application = $application;
}
/**
* 创建表单
*
* @param array|null $body
*
* @param Closure|null $catch
* @param Closure|null $then
* @return array
*
* @throws ApplicationException
* @throws SdkException
* @throws TimeOutExcetpion
*/
public function create(?array $body = [], ?Closure $catch = null, ?Closure $then = null): mixed
{
$url = "/api/form";
$request = new SdkRequest("POST", $url, "Test", "create", [], json_encode($body));
$request = $request->withArgs($this->ArgsRecoder(__METHOD__, func_get_args()))->withRequestID()->withAuthorization();
try {
$response = $this->application->sendRequest($request);
$decodedData = $this->application->resultDecode($request, $response);
$this->setLastResult($decodedData);
} catch (SdkException $sdkException) {
$this->setLastException($sdkException);
$catch = $catch ?? $this->defaultFailedCallBack();
return $catch($this);
}
$then = $then ?? $this->defaultSuccessCallBack();
return $then($this);
}
}
<?php
use Jiwei\EasyHttpSdk\Generation\SdkEndpointBuilder;
require_once __DIR__ . "/../vendor/autoload.php";
$params = getopt("d:e:p:h", [
"dist:",
"endpoints:",
"package:",
"help"
]);
if (isset($params['h']) || isset($params['help'])) {
echo "SDK生成工具🧸ver:0.1\n
-d --dist
输出SDK Endpoint 类的目录 默认为 src/Endpoint
-e --endpoints
获取endpoins toml 描述文件的目录 endpoints
-p--package
SDK Endpoint 类所使用的命名空间名称 ".PHP_EOL;
exit;
}
$packageName = $params['p'] ?? $params['package'] ?? "";
$distPath = $params['d'] ?? $params['dist'] ?? __DIR__ . "/../src/EndPoint/";
$endpointPath = $params['e'] ?? $params['endpoints'] ?? __DIR__ . "/../endpoints/";
if ("" === $packageName) {
echo "请输入的包名" . PHP_EOL;
exit;
}
var_dump($params);
echo "正在创建{$packageName}" . PHP_EOL;
echo "目标目录{$distPath}" . PHP_EOL;
echo "配置来源{$endpointPath}" . PHP_EOL;
$builder = new SdkEndpointBuilder(
$distPath,
$endpointPath,
__DIR__ . '/../template/',
$packageName
);
$count = $builder->build();
echo "成功生成{$count}个 Endpoint Class" . PHP_EOL;
\ No newline at end of file
{
"name": "jiwei/easy-http-sdk",
"description": "http client sdk generation.",
"type": "library",
"autoload": {
"psr-4": {
"Jiwei\\EasyHttpSdk\\": "src/"
}
},
"authors": [
{
"name": "谢宇轩",
"email": "y7ut1996@gmail.com"
}
],
"require": {
"php": ">7.2.5",
"psr/log": "^1.1",
"twig/twig": "^3.0",
"symfony/cache": "^5.4",
"yosymfony/toml": "^1.0",
"guzzlehttp/guzzle": "^7.5",
"ramsey/uuid": "^4.7",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9",
"phpstan/phpstan": "^1.9"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
"phpunit": "./vendor/bin/phpunit",
"phpunit-unit": "./vendor/bin/phpunit --testsuite=unit"
}
}
This diff is collapsed.
<?php
namespace Jiwei\EasyHttpSdk\Exception;
use GuzzleHttp\Exception\ConnectException;
use Jiwei\EasyHttpSdk\Helper\QueryPath;
use Jiwei\EasyHttpSdk\Http\SdkRequest;
use Throwable;
class ApplicationException extends ConnectException implements SdkExceptionInterface
{
use QueryPath;
/**
* @param string $message
* @param SdkRequest $request
* @param array<string, mixed> $handlerContext
* @param Throwable|null $previous
*/
public function __construct(
string $message,
SdkRequest $request,
array $handlerContext = [],
?\Throwable $previous = null,
) {
$this->endpoint = $request->getEndpoint();
$this->action = $request->getAction();
parent::__construct($message, $request, $previous, $handlerContext);
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Exception;
use GuzzleHttp\Exception\BadResponseException;
use Jiwei\EasyHttpSdk\Helper\QueryPath;
use Jiwei\EasyHttpSdk\Http\SdkRequest;
use Psr\Http\Message\ResponseInterface;
use Throwable;
class SdkException extends BadResponseException implements SdkExceptionInterface
{
use QueryPath;
/**
* @param string $message
* @param SdkRequest $request
* @param ResponseInterface $response
* @param array<string, mixed> $handlerContext
* @param Throwable|null $previous
*/
public function __construct(
string $message,
SdkRequest $request,
ResponseInterface $response,
array $handlerContext = [],
?\Throwable $previous = null
)
{
$this->endpoint = $request->getEndpoint();
$this->action = $request->getAction();
parent::__construct($message, $request, $response, $previous, $handlerContext);
}
/**
* 获取上下文中错误集合
*
* @return array<string, mixed>
*/
public function getSdkErrors(): array
{
return $this->getHandlerContext();
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Exception;
interface SdkExceptionInterface
{
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Exception;
use Jiwei\EasyHttpSdk\Http\SdkRequest;
use Throwable;
class TimeOutExcetpion extends ApplicationException implements SdkExceptionInterface
{
/** @var int 错误码 */
protected $code = 408;
/** @var string The error message */
protected $message = "time out.";
/**
* @param SdkRequest $request
* @param Throwable|null $previous
*/
public function __construct(
SdkRequest $request,
?\Throwable $previous = null,
)
{
parent::__construct($this->message, $request, [], $previous);
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Jiwei\EasyHttpSdk\Generation;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
use Yosymfony\Toml\Toml;
class SdkEndpointBuilder
{
/** @var string Toml目录 */
private $endpointSrcPath;
/** @var string 目标Endpoint目录 */
private $endpointDstPath;
/** @var string twig模板目录 */
private $twigPath;
/** @var array<string, mixed> 读取的配置 */
protected $tomlSetting = [];
/** @var Environment twig生成器 */
protected $twig;
/** @var string 包命名空间 */
protected $package;
/**
* @param string $endpointDstPath
* @param string $endpointSrcPath
* @param string $twigPath
* @param string $package
*/
public function __construct(string $endpointDstPath, string $endpointSrcPath, string $twigPath, string $package)
{
$this->endpointDstPath = $endpointDstPath;
$this->endpointSrcPath = $endpointSrcPath;
$this->twigPath = $twigPath;
$this->package = $package;
$loader = new FilesystemLoader($this->twigPath);
$this->twig = new Environment($loader);
}
/**
* 加载目录
*
* @return void
*/
private function LoadToml(): void
{
$dh = opendir($this->endpointSrcPath);
if (!$dh) {
throw new \RuntimeException(sprintf("src path [%s] can not open ", $this->endpointSrcPath));
}
while (($file = readdir($dh)) !== false) {
if (in_array($file, [".", ".."])) {
continue;
}
$actions = [];
if (str_contains($file, ".toml")) {
$actions = Toml::ParseFile($this->endpointSrcPath . $file);
}
$endpointName = ucfirst(str_replace(".toml", "", $file));
$this->tomlSetting[$endpointName] = $actions;
}
closedir($dh);
}
/**
* 根据配置创建Endpoint类
*
* @return int
*/
public function build(): int
{
$this->LoadToml();
$renderResult = [];
foreach ($this->tomlSetting as $name => $endpoints) {
$endpointFunc = [];
foreach ($endpoints as $func => $endpoint) {
$description = $endpoint["description"] ?? $func;
$uri = $endpoint['endpoint'] ?? "";
if (empty($uri)) {
throw new \RuntimeException(sprintf("endpoint [%s] method %s required a uri ", $name, $func));
}
$method = $endpoint['method'] ?? "";
if (empty($method)) {
throw new \RuntimeException(sprintf("endpoint [%s] method %s required a http method ", $name, $func));
}
$query = $endpoint['query'] ?? [];
$body = $endpoint['body'] ?? false;
$cache = $endpoint['cache'] ?? false;
$auth = $endpoint['auth'] ?? false;
$args = "";
$params = [];
$middlewareRuleCode = "";
if ($auth) {
$middlewareRuleCode .= '->withAuthorization()';
}
$require_regex = '~{([\w.]+)}~s';
$matched = preg_match_all($require_regex, $uri, $matches);
// 检测重复元素
if ($matched != count(array_unique($matches[1]))){
throw new \RuntimeException(sprintf("endpoint [%s] method %s required has same args ", $name, $func));
}
if ($matched > 0) {
foreach ($matches[1] as $item) {
$args .= 'string $' . $item . ', ';
$params[] = [
"type" => "string",
"name" => '$' . $item,
];
if (!str_contains($uri, "{$item}")) {
throw new \RuntimeException(sprintf("endpoint [%s] method %s required argument not found in uri ", $name, $func));
}
$uri = str_replace("{" . $item . "}", '{$' . $item . '}', $uri);
}
}
if ($cache) {
$args .= '?string $version = "", ';
$params[] = [
"type" => "string|null",
"name" => '$version',
];
$middlewareRuleCode .= '->withEtag($version)';
}
$queryJoin = [];
if (count($query) != count(array_unique($query))){
throw new \RuntimeException(sprintf("endpoint [%s] method %s query has same args ", $name, $func));
}
foreach ($query as $item) {
$args .= '?string $' . $item . ' = "", ';
$params[] = [
"type" => "string|null",
"name" => '$' . $item,
];
$queryJoin[] = [
"name" => "$" . $item,
"query" => sprintf('"%s={%s}&"', $item, "$" . $item),
];
}
$bodyStr = "";
if ($body) {
$args .= '?array $body = [], ';
$bodyStr = ', json_encode($body)';
$params[] = [
"type" => "array|null",
"name" => '$body',
];
}
$currentFunc = [
"Action" => $func,
"Description" => $description,
"Method" => $method,
"Uri" => $uri,
"Body" => $bodyStr,
"Args" => $args,
"Params" => $params,
"Middleware" => $middlewareRuleCode,
"Join" => $queryJoin,
];
$endpointFunc[] = $currentFunc;
}
$endpointSchema = [
"Endpoint" => $name,
"Package" => $this->package,
"Func" => $endpointFunc,
];
try {
$phpCode = $this->twig->render('Endpoint.temp', $endpointSchema);
$renderResult[$name] = $phpCode;
echo sprintf("Render Class[%s] ...", $name) . PHP_EOL;
} catch (LoaderError|RuntimeError|SyntaxError $e) {
echo sprintf("Render Error : %s", $e->getRawMessage()) . PHP_EOL;
}
}
foreach ($renderResult as $name => $phpCode) {
file_put_contents($this->endpointDstPath . $name . ".php", $phpCode);
echo sprintf("Save Class[%s] ...", $name) . PHP_EOL;
}
return count($this->tomlSetting);
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Helper;
trait ArgsRecorder
{
/**
* @param string $func
* @param array $params
* @return array
*/
private function ArgsRecoder(string $func, array $params): array
{
$result = [];
try {
$reflectionFunction = new \ReflectionMethod($func);
foreach ($reflectionFunction->getParameters() as $key => $parameter) {
$result[$parameter->name] = $params[$key] ?? null;
}
}catch (\ReflectionException $exception) {
throw new \RuntimeException("Refection get args error.");
}
return $result;
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Helper;
use Closure;
use Jiwei\EasyHttpSdk\Exception\SdkException;
trait CallBackHelper
{
/**
* @var SdkException|null
*/
private $lastException = null;
/**
* @var mixed
*/
private $lastResult = [];
/**
* @return mixed
*/
public function getLastResult()
{
return $this->lastResult;
}
/**
* @param mixed $lastResult
*/
public function setLastResult($lastResult): void
{
$this->lastResult = $lastResult;
}
/**
* @return SdkException|null
*/
public function getLastException(): ?SdkException
{
return $this->lastException;
}
/**
* @param SdkException $lastException
*/
public function setLastException(SdkException $lastException): void
{
$this->lastException = $lastException;
}
/**
* @return Closure
*/
public function defaultSuccessCallBack(): Closure
{
// 这里使用默认作用域
return function () {
return $this->getLastResult();
};
}
/**
* @return Closure
*/
public function defaultFailedCallBack(): Closure
{
// 这里使用默认作用域
return function () {
throw $this->getLastException();
};
}
/**
* @return array
*/
public function getContext(): array
{
return array_merge($this->application->getLastRequestContext(), [
'data' => $this->getLastResult(),
'exception' => $this->getLastException(),
]);
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Helper;
trait QueryPath
{
/** @var string Endpoint */
protected $endpoint;
/** @var string Endpoint */
protected $action;
/**
* 获取错误详情位置
*
* @return string
*/
public function getPath(): string
{
return $this->endpoint . ":" . $this->action;
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Jiwei\EasyHttpSdk\Http;
use GuzzleHttp\Psr7\Request;
use Jiwei\EasyHttpSdk\Middleware\EtagMiddleware;
use Jiwei\EasyHttpSdk\Middleware\MiddlewareInterface;
use Jiwei\EasyHttpSdk\Middleware\RequestIDMiddleware;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
class SdkRequest extends Request
{
/** @var string SDK uuid */
private $uuid;
/** @var string SDK Endpoint */
private $endpoint;
/** @var string SDK方法 */
private $action;
/** @var float 开始时间 */
private $startAt;
/** @var array<string, mixed> 调用参数列表 */
private $args;
/** @var MiddlewareInterface[] Guzzle中间件列表 */
private $middlewares = [];
/** @var bool 鉴权开关 */
private $authorization = false;
/**
* Construct of SdkRequest style by psr-7
*
* @param string $method HTTP method
* @param string|UriInterface $uri URI
* @param string $endpoint Endponit
* @param string $action action
* @param array<string, string|string[]> $headers Request headers
* @param string|resource|StreamInterface|null $body Request body
* @param string $version Protocol version
*/
public function __construct(
string $method,
$uri,
$endpoint,
$action,
array $headers = [],
$body = null,
string $version = '1.1'
)
{
parent::__construct($method, $uri, $headers, $body, $version);
$this->startAt = microtime(true);
$this->endpoint = $endpoint;
$this->action = $action;
}
/**
* 获取本次请求的方法参数
*
* @return array<string, mixed>
*/
public function getArgs(): array
{
return $this->args;
}
/**
* 设置本次请求的方法参数
*
* @param array<string, mixed> $args
* @return SdkRequest
*/
public function withArgs(array $args): self
{
$this->args = $args;
return $this;
}
/**
* 获取本次请求需要使用的中间件
*
* @return MiddlewareInterface[]
*/
public function getMiddlewares(): array
{
return $this->middlewares;
}
/**
* 获取 SDK Endpoint
*
* @return string
*/
public function getEndpoint(): string
{
return $this->endpoint;
}
/**
* 获取 SDK Action
*
* @return string
*/
public function getAction(): string
{
return $this->action;
}
/**
* 判断鉴权
*
* @return bool
*/
public function authorization(): bool
{
return $this->authorization;
}
/**
* 开启鉴权
*
* @return SdkRequest
*/
public function withAuthorization(): self
{
$this->authorization = true;
return $this;
}
/**
* 使用ETAG中间件来传递version
*
* @param string $version
* @return SdkRequest
*/
public function withEtag(string $version): self
{
$EtgMiddleware = new EtagMiddleware($version);
$this->middlewares[] = $EtgMiddleware;
return $this;
}
/**
* 获取请求ID
*
* @return string
*/
public function getUuid(): string
{
return $this->uuid;
}
/**
* 使用 RequestID 中间件
*
* @param string|null $uuid
* @return SdkRequest
*/
public function withRequestID(?string $uuid = null): self
{
$this->uuid = $uuid;
$RequestIDMiddleware = new RequestIDMiddleware($this->uuid);
$this->middlewares[] = $RequestIDMiddleware;
return $this;
}
/**
* 获取初始化时间
*
* @return float
*/
public function getStartAt(): float
{
return $this->startAt;
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Middleware;
use Psr\Http\Message\RequestInterface;
class EtagMiddleware implements MiddlewareInterface
{
/** @var string Version */
private $version;
/**
* @param string $version
*/
public function __construct(string $version)
{
$this->version = $version;
}
/**
* 为请求添加Etag的中间件
*
* @param callable $handler
* @return callable
*/
public function __invoke(callable $handler): callable
{
return function (
RequestInterface $request,
array $options
) use ($handler) {
if ($this->version !== "") {
$ETagHeaderAttribute = "If-Match";
if ($request->getMethod() == "GET") {
$ETagHeaderAttribute = "If-None-Match";
}
$request = $request->withHeader($ETagHeaderAttribute, $this->version);
}
return $handler($request, $options);
};
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Middleware;
use Psr\Http\Message\RequestInterface;
class JwtMiddleware implements MiddlewareInterface
{
/** @var string jwtToken */
protected $token;
public function __construct(string $token){
$this->token = $token;
}
/**
* 为请求添加Jwt Token的中间件
*
* @param callable $handler
* @return callable
*/
public function __invoke(callable $handler): callable
{
return function (
RequestInterface $request,
array $options
) use ($handler) {
$request = $request->withHeader("Authorization", "Bearer " . $this->token );
return $handler($request, $options);
};
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Middleware;
interface MiddlewareInterface
{
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk\Middleware;
use Psr\Http\Message\RequestInterface;
use Ramsey\Uuid\Uuid;
class RequestIDMiddleware implements MiddlewareInterface
{
/** @var string UUID */
protected $uuid;
/**
* @param string|null $uuid
*/
public function __construct(string $uuid = null){
if (!$uuid) {
$uuid = substr(Uuid::uuid4()->toString(), 0, 8);
}
$this->uuid = $uuid;
}
/**
* 为请求添加ID的中间件
*
* @param callable $handler
* @return callable
*/
public function __invoke(callable $handler): callable
{
return function (
RequestInterface $request,
array $options
) use ($handler) {
$request = $request->withHeader("X-Request-ID", $this->uuid);
return $handler($request, $options);
};
}
}
\ No newline at end of file
<?php
namespace Jiwei\EasyHttpSdk;
use GuzzleHttp\Psr7\Request;
use http\Exception\InvalidArgumentException;
abstract class Option
{
const ENDPONIT_HOSTS = [
'local' => '',
'development' => '',
'production' => ''
];
/** @var string App Key 应用标志 */
private $app_id;
/** @var string App Secret 应用密钥 */
private $app_secret;
/** @var string SDK 的 Stage 环境 */
private $stage = "development";
/** @var float 超时时间 */
private $time_out = 3.0;
/** @var bool 调试模式 */
private $debug = false;
/**
* @return \Closure
*/
abstract public function getAuthMoudel(): \Closure;
/**
* @param string $app_id
* @return Option
*/
public function setAppId(string $app_id): self
{
$this->app_id = $app_id;
return $this;
}
/**
* @param string $app_secret
* @return Option
*/
public function setAppSecret(string $app_secret): self
{
$this->app_secret = $app_secret;
return $this;
}
/**
* @param string $stage
* @return Option
*/
public function setStage(string $stage): self
{
$this->stage = $stage;
return $this;
}
/**
* @param float $time_out
* @return Option
*/
public function setTimeout(float $time_out): self
{
$this->time_out = $time_out;
return $this;
}
/**
* @param bool $debug
* @return Option
*/
public function setDebug(bool $debug): self
{
$this->debug = $debug;
return $this;
}
/**
* @return string
*/
public function getAppSecret(): string
{
return $this->app_secret;
}
/**
* @return string
*/
public function getBaseUrl(): string
{
return self::ENDPONIT_HOSTS[$this->getStage()] ?? "";
}
/**
* @return string
*/
public function getStage(): string
{
return $this->stage;
}
/**
* @return float
*/
public function getTimeOut(): float
{
return $this->time_out;
}
/**
* @return string
*/
public function getAppId(): string
{
return $this->app_id;
}
/**
* @return bool
*/
public function isDebug(): bool
{
return $this->debug;
}
}
<?php
namespace Jiwei\EasyHttpSdk;
use GuzzleHttp\Psr7\Request;
class XXXSDKOption extends Option
{
private const AUTH_API_ROUTE = "/api/access/token";
const ENDPONIT_HOSTS = [
'local' => 'localhost:8080',
'development' => 'localhost:8080',
'production' => 'localhost:8080'
];
public function getAuthMoudel(): \Closure
{
return function (string $appId, string $appSecret): Request {
return new Request('post', self::AUTH_API_ROUTE, [
"body" => json_encode([
"app_key" => $appId,
"app_secret" => $appSecret
])
]);
};
}
}
{% autoescape false %}
<?php
// generated code, do not edit.
declare(strict_types=1);
namespace Jiwei\{{ Package }}\Endpoint;
use Closure;
use Jiwei\EasyHttpSdk\Application;
use Jiwei\EasyHttpSdk\Exception\SdkException;
use Jiwei\EasyHttpSdk\Exception\ApplicationException;
use Jiwei\EasyHttpSdk\Exception\TimeOutExcetpion;
use Jiwei\EasyHttpSdk\Helper\ArgsRecorder;
use Jiwei\EasyHttpSdk\Helper\CallBackHelper;
use Jiwei\EasyHttpSdk\Http\SdkRequest;
class {{ Endpoint }}
{
use ArgsRecorder;
use CallBackHelper;
/** @var Application */
protected $application;
/**
* @param Application $application
*/
public function __construct(
Application $application
)
{
$this->application = $application;
}
{% for item in Func %}
/**
* {{ item.Description }}
*
{% for param in item.Params %}
* @param {{ param.type }} {{ param.name }}
{% endfor %}
*
* @param Closure|null $catch
* @param Closure|null $then
* @return array
*
* @throws ApplicationException
* @throws SdkException
* @throws TimeOutExcetpion
*/
public function {{ item.Action }}({{ item.Args }}?Closure $catch = null, ?Closure $then = null): mixed
{
$url = "{{ item.Uri }}";
{% if item.Join|length > 0 %}
$url .= "?";
{% endif%}
{% for join in item.Join %}
if ({{ join.name }} != "") {
$url .= {{ join.query }};
}
{% endfor %}
$request = new SdkRequest("{{ item.Method }}", $url, "{{ Endpoint }}", "{{ item.Action }}", []{{ item.Body }});
$request = $request->withArgs($this->ArgsRecoder(__METHOD__, func_get_args()))->withRequestID(){{ item.Middleware }};
try {
$response = $this->application->sendRequest($request);
$decodedData = $this->application->resultDecode($request, $response);
$this->setLastResult($decodedData);
} catch (SdkException $sdkException) {
$this->setLastException($sdkException);
$catch = $catch ?? $this->defaultFailedCallBack();
return $catch($this);
}
$then = $then ?? $this->defaultSuccessCallBack();
return $then($this);
}
{% endfor %}
}
{% endautoescape %}
\ No newline at end of file
<?php
use PHPUnit\Framework\TestCase;
final class ApplicationTest extends TestCase
{
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment