first commit
This commit is contained in:
33
vendor/yansongda/pay/src/Parser/ArrayParser.php
vendored
Normal file
33
vendor/yansongda/pay/src/Parser/ArrayParser.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Parser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Yansongda\Pay\Contract\ParserInterface;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Exception\InvalidResponseException;
|
||||
|
||||
class ArrayParser implements ParserInterface
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidResponseException
|
||||
*/
|
||||
public function parse(?ResponseInterface $response): array
|
||||
{
|
||||
if (is_null($response)) {
|
||||
throw new InvalidResponseException(Exception::RESPONSE_NONE);
|
||||
}
|
||||
|
||||
$contents = $response->getBody()->getContents();
|
||||
|
||||
$result = json_decode($contents, true);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['contents' => $contents, 'response' => $response]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
25
vendor/yansongda/pay/src/Parser/CollectionParser.php
vendored
Normal file
25
vendor/yansongda/pay/src/Parser/CollectionParser.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Parser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Yansongda\Pay\Contract\ParserInterface;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class CollectionParser implements ParserInterface
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
public function parse(?ResponseInterface $response): Collection
|
||||
{
|
||||
return new Collection(
|
||||
Pay::get(ArrayParser::class)->parse($response)
|
||||
);
|
||||
}
|
||||
}
|
||||
16
vendor/yansongda/pay/src/Parser/NoHttpRequestParser.php
vendored
Normal file
16
vendor/yansongda/pay/src/Parser/NoHttpRequestParser.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Parser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Yansongda\Pay\Contract\ParserInterface;
|
||||
|
||||
class NoHttpRequestParser implements ParserInterface
|
||||
{
|
||||
public function parse(?ResponseInterface $response): ?ResponseInterface
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
25
vendor/yansongda/pay/src/Parser/OriginResponseParser.php
vendored
Normal file
25
vendor/yansongda/pay/src/Parser/OriginResponseParser.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Parser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Yansongda\Pay\Contract\ParserInterface;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Exception\InvalidResponseException;
|
||||
|
||||
class OriginResponseParser implements ParserInterface
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidResponseException
|
||||
*/
|
||||
public function parse(?ResponseInterface $response): ?ResponseInterface
|
||||
{
|
||||
if (!is_null($response)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
throw new InvalidResponseException(Exception::INVALID_RESPONSE_CODE);
|
||||
}
|
||||
}
|
||||
9
vendor/yansongda/pay/src/Parser/ResponseParser.php
vendored
Normal file
9
vendor/yansongda/pay/src/Parser/ResponseParser.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Parser;
|
||||
|
||||
class ResponseParser extends NoHttpRequestParser
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user