diff --git a/src/Events.php b/src/Events.php index 3f70d8e..96e1269 100644 --- a/src/Events.php +++ b/src/Events.php @@ -2,23 +2,37 @@ namespace Yansongda\Pay; +use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +/** + * @author yansongda + * + * @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. diff --git a/src/Events/BeforePay.php b/src/Events/PayStarted.php similarity index 95% rename from src/Events/BeforePay.php rename to src/Events/PayStarted.php index 8d59070..c7f2c0f 100644 --- a/src/Events/BeforePay.php +++ b/src/Events/PayStarted.php @@ -2,7 +2,7 @@ namespace Yansongda\Pay\Events; -class BeforePay extends Event +class PayStarted extends Event { /** * Endpoint. diff --git a/src/Events/StartingPay.php b/src/Events/PayStarting.php similarity index 92% rename from src/Events/StartingPay.php rename to src/Events/PayStarting.php index ca7ed20..c44a540 100644 --- a/src/Events/StartingPay.php +++ b/src/Events/PayStarting.php @@ -2,7 +2,7 @@ namespace Yansongda\Pay\Events; -class StartingPay extends Event +class PayStarting extends Event { /** * Params. diff --git a/src/Listeners/KernelSubscriber.php b/src/Listeners/KernelSubscriber.php index 6de4f95..bf1fd67 100644 --- a/src/Listeners/KernelSubscriber.php +++ b/src/Listeners/KernelSubscriber.php @@ -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) { } diff --git a/src/Pay.php b/src/Pay.php index 2c47eef..2022f1d 100644 --- a/src/Pay.php +++ b/src/Pay.php @@ -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()); } }