This commit is contained in:
yansongda 2018-12-12 15:03:50 +08:00
parent c201f781d4
commit f0e6dc024a
5 changed files with 31 additions and 14 deletions

View File

@ -2,23 +2,37 @@
namespace Yansongda\Pay;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @author yansongda <me@yansongda.cn>
*
* @method static Event dispatch($eventName, Event $event = null) Dispatches an event to all registered listeners
* @method static array getListeners($eventName = null) Gets the listeners of a specific event or all listeners sorted by descending priority.
* @method static int|null getListenerPriority($eventName, $listener) Gets the listener priority for a specific event.
* @method static bool hasListeners($eventName = null) Checks whether an event has any registered listeners.
* @method static addListener($eventName, $listener, $priority = 0) Adds an event listener that listens on the specified events.
* @method static removeListener($eventName, $listener) Removes an event listener from the specified events.
* @method static addSubscriber(EventSubscriberInterface $subscriber) Adds an event subscriber.
* @method static removeSubscriber(EventSubscriberInterface $subscriber)
*/
class Events
{
/**
* Start pay.
*
* @Event("Yansongda\Pay\Events\StartingPay")
* @Event("Yansongda\Pay\Events\PayStarting")
*/
const STARTING_PAY = 'yansongda.pay.starting';
const PAY_STARTING = 'yansongda.pay.starting';
/**
* Before pay.
*
* @Event("Yansongda\Pay\Events\PayBefore")
* @Event("Yansongda\Pay\Events\PayStarted")
*/
const BEFORE_PAY = 'yansongda.pay.before';
const PAY_STARTED = 'yansongda.pay.started';
/**
* Paying.

View File

@ -2,7 +2,7 @@
namespace Yansongda\Pay\Events;
class BeforePay extends Event
class PayStarted extends Event
{
/**
* Endpoint.

View File

@ -2,7 +2,7 @@
namespace Yansongda\Pay\Events;
class StartingPay extends Event
class PayStarting extends Event
{
/**
* Params.

View File

@ -28,17 +28,17 @@ class KernelSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents ()
{
return [
Events::STARTING_PAY => [],
Events::BEFORE_PAY => [],
Events::API_REQUESTING => [],
Events::API_REQUESTED => [],
Events::SIGN_FAILED => [],
Events::REQUEST_RECEIVED => [],
Events::METHOD_CALLED => []
Events::PAY_STARTING => ['writeLog', 256],
Events::PAY_STARTED => ['writeLog', 256],
Events::API_REQUESTING => ['writeLog', 256],
Events::API_REQUESTED => ['writeLog', 256],
Events::SIGN_FAILED => ['writeLog', 256],
Events::REQUEST_RECEIVED => ['writeLog', 256],
Events::METHOD_CALLED => ['writeLog', 256]
];
}
public function WriteLog()
public function writeLog(Events\Event $event)
{
}

View File

@ -6,6 +6,7 @@ use Yansongda\Pay\Contracts\GatewayApplicationInterface;
use Yansongda\Pay\Exceptions\InvalidGatewayException;
use Yansongda\Pay\Gateways\Alipay;
use Yansongda\Pay\Gateways\Wechat;
use Yansongda\Pay\Listeners\KernelSubscriber;
use Yansongda\Supports\Config;
use Yansongda\Supports\Log;
use Yansongda\Supports\Str;
@ -134,5 +135,7 @@ class Pay
protected function registerEventService()
{
Events::setDispatcher(Events::createDispatcher());
Events::addSubscriber(new KernelSubscriber());
}
}