change(internal): DirectionInterface 方法由 parse 改为 guide (#896)

This commit is contained in:
yansongda 2023-12-22 15:11:53 +08:00 committed by GitHub
parent c44a4fc1f4
commit 6259850960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 14 deletions

View File

@ -5,6 +5,7 @@
- change(internal): shortcut 完整标明各个插件,不使用 commonPlugin(#886)
- change(internal): 按场景对支付宝插件进行分类(#894)
- change(internal): 支付宝 shortcut 从 plugin 文件夹独立出来(#895)
- change(internal): DirectionInterface 方法由 `parse` 改为 `guide`(#896)
## v3.5.3

View File

@ -8,5 +8,5 @@ use Psr\Http\Message\ResponseInterface;
interface DirectionInterface
{
public function parse(PackerInterface $packer, ?ResponseInterface $response): mixed;
public function guide(PackerInterface $packer, ?ResponseInterface $response): mixed;
}

View File

@ -16,7 +16,7 @@ class CollectionDirection implements DirectionInterface
/**
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): Collection
public function guide(PackerInterface $packer, ?ResponseInterface $response): Collection
{
if (is_null($response)) {
throw new InvalidResponseException(Exception::RESPONSE_NONE);

View File

@ -10,7 +10,7 @@ use Yansongda\Pay\Contract\PackerInterface;
class NoHttpRequestDirection implements DirectionInterface
{
public function parse(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
public function guide(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
{
return $response;
}

View File

@ -15,7 +15,7 @@ class OriginResponseDirection implements DirectionInterface
/**
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
public function guide(PackerInterface $packer, ?ResponseInterface $response): ?ResponseInterface
{
if (!is_null($response)) {
return $response;

View File

@ -36,7 +36,7 @@ class ParserPlugin implements PluginInterface
$response = $rocket->getDestination();
$rocket->setDestination(
get_direction($rocket->getDirection())->parse($this->getPacker($rocket), $response)
get_direction($rocket->getDirection())->guide($this->getPacker($rocket), $response)
);
Logger::debug('[ParserPlugin] 插件装载完毕', ['rocket' => $rocket]);

View File

@ -25,7 +25,7 @@ class CollectionDirectionTest extends TestCase
{
$response = new Response(200, [], '{"name": "yansongda"}');
$result = $this->parser->parse(new JsonPacker(), $response);
$result = $this->parser->guide(new JsonPacker(), $response);
self::assertEquals(['name' => 'yansongda'], $result->all());
}
@ -35,7 +35,7 @@ class CollectionDirectionTest extends TestCase
self::expectException(InvalidResponseException::class);
self::expectExceptionCode(Exception::RESPONSE_NONE);
$this->parser->parse(new JsonPacker(), null);
$this->parser->guide(new JsonPacker(), null);
}
public function testWrongFormat()
@ -45,7 +45,7 @@ class CollectionDirectionTest extends TestCase
$response = new Response(200, [], '{"name": "yansongda"}a');
$this->parser->parse(new JsonPacker(), $response);
$this->parser->guide(new JsonPacker(), $response);
}
public function testReadContents()
@ -54,7 +54,7 @@ class CollectionDirectionTest extends TestCase
$response->getBody()->read(2);
$result = $this->parser->parse(new JsonPacker(), $response);
$result = $this->parser->guide(new JsonPacker(), $response);
self::assertEquals(['name' => 'yansongda'], $result->toArray());
}
@ -63,7 +63,7 @@ class CollectionDirectionTest extends TestCase
{
$response = new Response(200, [], 'name=yansongda&age=29');
$result = $this->parser->parse(new QueryPacker(), $response);
$result = $this->parser->guide(new QueryPacker(), $response);
self::assertEqualsCanonicalizing(['name' => 'yansongda', 'age' => '29'], $result->toArray());
}
@ -74,7 +74,7 @@ class CollectionDirectionTest extends TestCase
$response = new Response(200, [], json_encode(['h5_url' => $url]));
$result = $this->parser->parse(new JsonPacker(), $response);
$result = $this->parser->guide(new JsonPacker(), $response);
self::assertEquals('https://yansongda.cn?name=yansongda&age=29', $result['h5_url']);
}

View File

@ -22,14 +22,14 @@ class NoHttpRequestDirectionTest extends TestCase
{
$response = new Response(200, [], '{"name": "yansongda"}');
$result = $this->parser->parse(new JsonPacker(), $response);
$result = $this->parser->guide(new JsonPacker(), $response);
self::assertSame($response, $result);
}
public function testNull()
{
$result = $this->parser->parse(new JsonPacker(), null);
$result = $this->parser->guide(new JsonPacker(), null);
self::assertNull($result);
}

View File

@ -24,6 +24,6 @@ class OriginResponseDirectionTest extends TestCase
self::expectException(InvalidResponseException::class);
self::expectExceptionCode(Exception::INVALID_RESPONSE_CODE);
$this->parser->parse(new JsonPacker(), null);
$this->parser->guide(new JsonPacker(), null);
}
}