Completed
Push — master ( 56c44b...57c31b )
by Songda
05:33 queued 11s
created

AppShortcut::getPlugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Alipay\Shortcut;
6
7
use Closure;
8
use GuzzleHttp\Psr7\Response;
9
use Yansongda\Pay\Contract\PluginInterface;
10
use Yansongda\Pay\Contract\ShortcutInterface;
11
use Yansongda\Pay\Plugin\Alipay\Trade\AppPayPlugin;
12
use Yansongda\Pay\Rocket;
13
use Yansongda\Supports\Arr;
14
use Yansongda\Supports\Collection;
15
16
class AppShortcut implements ShortcutInterface
17
{
18
    public function getPlugins(): array
19
    {
20
        return [
21
            AppPayPlugin::class,
22
            $this->buildResponse(),
23
        ];
24
    }
25
26
    protected function buildResponse(): PluginInterface
27
    {
28
        return new class() implements PluginInterface {
29
            public function assembly(Rocket $rocket, Closure $next): Rocket
30
            {
31
                $rocket->setDestination(new Response());
32
33
                /* @var Rocket $rocket */
34
                $rocket = $next($rocket);
35
36
                $response = $this->buildHtml($rocket->getPayload());
37
38
                return $rocket->setDestination($response);
39
            }
40
41
            protected function buildHtml(Collection $payload): Response
42
            {
43
                return new Response(200, [], Arr::query($payload->all()));
44
            }
45
        };
46
    }
47
}
48