Completed
Push — master ( 1ec9e3...ab571a )
by Songda
03:58
created

KernelLogSubscriber::writePayStartingLog()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yansongda\Pay\Listeners;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Log;
8
9
class KernelLogSubscriber implements EventSubscriberInterface
10
{
11
    /**
12
     * Returns an array of event names this subscriber wants to listen to.
13
     *
14
     * The array keys are event names and the value can be:
15
     *
16
     *  * The method name to call (priority defaults to 0)
17
     *  * An array composed of the method name to call and the priority
18
     *  * An array of arrays composed of the method names to call and respective
19
     *    priorities, or 0 if unset
20
     *
21
     * For instance:
22
     *
23
     *  * array('eventName' => 'methodName')
24
     *  * array('eventName' => array('methodName', $priority))
25
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
26
     *
27
     * @return array The event names to listen to
28
     */
29
    public static function getSubscribedEvents()
30
    {
31
        return [
32
            Events::PAY_STARTING => ['writePayStartingLog', 256],
33
            Events::PAY_STARTED => ['writePayStartedLog', 256],
34
            Events::API_REQUESTING => ['writeApiRequestingLog', 256],
35
            Events::API_REQUESTED => ['writeApiRequestedLog', 256],
36
            Events::SIGN_FAILED => ['writeSignFailedLog', 256],
37
            Events::REQUEST_RECEIVED => ['writeRequestReceivedLog', 256],
38
            Events::METHOD_CALLED => ['writeMethodCalledLog', 256]
39
        ];
40
    }
41
42
    /**
43
     * writePayStartingLog.
44
     *
45
     * @author yansongda <[email protected]>
46
     *
47
     * @param Events\PayStarting $event
48
     *
49
     * @return void
50
     */
51
    public function writePayStartingLog(Events\PayStarting $event)
52
    {
53
        Log::debug("Starting To {$event->driver}", [$event->gateway, $event->params]);
54
    }
55
56
    /**
57
     * writePayStartedLog.
58
     *
59
     * @author yansongda <[email protected]>
60
     *
61
     * @param Events\PayStarted $event
62
     *
63
     * @return void
64
     */
65
    public function writePayStartedLog(Events\PayStarted $event)
66
    {
67
        Log::info(
68
            "{$event->driver} {$event->gateway} Has Started",
69
            [$event->endpoint, $event->payload]
70
        );
71
    }
72
73
    /**
74
     * writeApiRequestingLog.
75
     *
76
     * @author yansongda <[email protected]>
77
     *
78
     * @param Events\ApiRequesting $event
79
     *
80
     * @return void
81
     */
82
    public function writeApiRequestingLog(Events\ApiRequesting $event)
83
    {
84
        Log::debug("Requesting To {$event->driver} Api", [$event->endpoint, $event->payload]);
85
    }
86
87
    /**
88
     * writeApiRequestedLog.
89
     *
90
     * @author yansongda <[email protected]>
91
     *
92
     * @param Events\ApiRequested $event
93
     *
94
     * @return void
95
     */
96
    public function writeApiRequestedLog(Events\ApiRequested $event)
97
    {
98
        Log::debug("Result Of {$event->driver} Api", $event->result);
99
    }
100
101
    /**
102
     * writeSignFailedLog.
103
     *
104
     * @author yansongda <[email protected]>
105
     *
106
     * @param Events\SignFailed $event
107
     *
108
     * @return void
109
     */
110
    public function writeSignFailedLog(Events\SignFailed $event)
111
    {
112
        Log::warning("{$event->driver} Sign Verify FAILED", $event->data);
113
    }
114
115
    /**
116
     * writeRequestReceivedLog.
117
     *
118
     * @author yansongda <[email protected]>
119
     *
120
     * @param Events\RequestReceived $event
121
     *
122
     * @return void
123
     */
124
    public function writeRequestReceivedLog(Events\RequestReceived $event)
125
    {
126
        Log::info("Received {$event->driver} Request", $event->data);
127
    }
128
129
    /**
130
     * writeMethodCalledLog.
131
     *
132
     * @author yansongda <[email protected]>
133
     *
134
     * @param Events\MethodCalled $event
135
     *
136
     * @return void
137
     */
138
    public function writeMethodCalledLog(Events\MethodCalled $event)
139
    {
140
        Log::info("{$event->driver} {$event->gateway} Method Has Called", [$event->endpoint, $event->payload]);
141
    }
142
}
143