代码初始化

This commit is contained in:
2025-08-07 20:21:47 +08:00
commit 50f3a2dbb0
2191 changed files with 374790 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Contract\PackerInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
class ArrayDirection implements DirectionInterface
{
/**
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): array
{
if (is_null($response)) {
throw new InvalidResponseException(Exception::RESPONSE_NONE);
}
$body = (string) $response->getBody();
if (!is_null($result = $packer->unpack($body))) {
return $result;
}
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Contract\PackerInterface;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\ServiceNotFoundException;
use Yansongda\Pay\Pay;
use Yansongda\Supports\Collection;
class CollectionDirection implements DirectionInterface
{
/**
* @throws ContainerException
* @throws ServiceNotFoundException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): Collection
{
return new Collection(
Pay::get(ArrayDirection::class)->parse($packer, $response)
);
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Contract\PackerInterface;
class NoHttpRequestDirection implements DirectionInterface
{
public function parse(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
{
return $response;
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
use Psr\Http\Message\ResponseInterface;
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Contract\PackerInterface;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
class OriginResponseDirection implements DirectionInterface
{
/**
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
{
if (!is_null($response)) {
return $response;
}
throw new InvalidResponseException(Exception::INVALID_RESPONSE_CODE);
}
}

View File

@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Yansongda\Pay\Direction;
class ResponseDirection extends NoHttpRequestDirection
{
}