Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete: 移除 Yansongda\Pay\Direction\ArrayDirection #818

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v3.5.0

### deleted

- deleted: 移除 `Yansongda\Pay\Direction\ArrayDirection` 类(#818)

## v3.4.2

### changed
Expand Down
32 changes: 0 additions & 32 deletions src/Direction/ArrayDirection.php

This file was deleted.

22 changes: 14 additions & 8 deletions src/Direction/CollectionDirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@
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\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
use Yansongda\Supports\Collection;

class CollectionDirection implements DirectionInterface
{
/**
* @throws ContainerException
* @throws ServiceNotFoundException
* @throws InvalidResponseException
*/
public function parse(PackerInterface $packer, ?ResponseInterface $response): Collection
{
return new Collection(
Pay::get(ArrayDirection::class)->parse($packer, $response)
);
if (is_null($response)) {
throw new InvalidResponseException(Exception::RESPONSE_NONE);
}

$body = (string) $response->getBody();

if (!is_null($result = $packer->unpack($body))) {
return new Collection($result);
}

throw new InvalidResponseException(Exception::UNPACK_RESPONSE_ERROR, 'Unpack Response Error', ['body' => $body, 'response' => $response]);
}
}
9 changes: 1 addition & 8 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Contract\ProviderInterface;
use Yansongda\Pay\Contract\ShortcutInterface;
use Yansongda\Pay\Direction\ArrayDirection;
use Yansongda\Pay\Event;
use Yansongda\Pay\Exception\ContainerException;
use Yansongda\Pay\Exception\Exception;
Expand Down Expand Up @@ -77,13 +76,7 @@ public function pay(array $plugins, array $params): Collection|MessageInterface|

Event::dispatch(new Event\PayFinish($rocket));

$destination = $rocket->getDestination();

if (ArrayDirection::class === $rocket->getDirection() && $destination instanceof Collection) {
return $destination->toArray();
}

return $destination;
return $rocket->getDestination();
}

/**
Expand Down
81 changes: 0 additions & 81 deletions tests/Direction/ArrayDirectionTest.php

This file was deleted.

21 changes: 1 addition & 20 deletions tests/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Yansongda\Pay\Contract\PackerInterface;
use Yansongda\Pay\Contract\PluginInterface;
use Yansongda\Pay\Contract\ShortcutInterface;
use Yansongda\Pay\Direction\ArrayDirection;
use Yansongda\Pay\Direction\CollectionDirection;
use Yansongda\Pay\Direction\NoHttpRequestDirection;
use Yansongda\Pay\Exception\Exception;
Expand Down Expand Up @@ -121,23 +120,6 @@ public function testIgniteWrongHttpClient()
$provider->ignite($rocket);
}

public function testArrayDirection()
{
$response = new Response(200, [], '{"name":"yansongda"}');

$http = Mockery::mock(Client::class);
$http->shouldReceive('sendRequest')->andReturn($response);

Pay::set(HttpClientInterface::class, $http);

$plugin = [BarPlugin::class];

$provider = new FooProviderStub();
$result = $provider->pay($plugin, []);

self::assertIsArray($result);
}

public function testNoCommonPlugins()
{
$provider = new Foo2ProviderStub();
Expand Down Expand Up @@ -212,8 +194,7 @@ class BarPlugin implements PluginInterface
{
public function assembly(Rocket $rocket, Closure $next): Rocket
{
$rocket->setDirection(ArrayDirection::class)
->setRadar(new Request('get', ''));
$rocket->setRadar(new Request('get', ''));

$rocket = $next($rocket);

Expand Down
7 changes: 2 additions & 5 deletions web/docs/v3/quick-start/return-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ ThinkPHP 框架在 [https://github.com/top-think/framework/pull/2614](https://gi

## array

API 调用场景下的返回类型,`array` 和 `Collection` 是可以自定义的,默认情况下均返回 `Collection` 实例。
API 调用场景下的返回类型,默认情况下均返回 `Collection` 实例。

如果想返回 array 类型的数据,只需要

```php
use Yansongda\Pay\Contract\DirectionInterface;
use Yansongda\Pay\Direction\ArrayDirection;

Pay::set(DirectionInterface::class, ArrayDirection::class);
$collection->toArray();
```

是不是很简单方便?