From aeab7ba6c3dce5e336b0f6e8e9bbe32b9c808fe4 Mon Sep 17 00:00:00 2001 From: xujiajun Date: Tue, 17 Oct 2017 10:40:38 +0800 Subject: [PATCH] add register kernel listeners&&ServiceProvider wrapper --- src/Framework/Traits/KernelTrait.php | 101 ++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/src/Framework/Traits/KernelTrait.php b/src/Framework/Traits/KernelTrait.php index 1cfd222..b24f874 100644 --- a/src/Framework/Traits/KernelTrait.php +++ b/src/Framework/Traits/KernelTrait.php @@ -1,8 +1,19 @@ dispatch(AppEvent::RESPONSE, new \TastPHP\Framework\Event\HttpEvent(null, $this['router']->matchCurrentRequest(),$this)); + $httpEvent = $this['eventDispatcher']->dispatch(AppEvent::RESPONSE, new \TastPHP\Framework\Event\HttpEvent(null, $this['router']->matchCurrentRequest(), $this)); if (!empty($this['swoole'])) { return $httpEvent; } @@ -146,4 +157,92 @@ public function getListeners($key = '') return $this->listeners; } + + //ServiceProvider register + + protected function registerRedisService() + { + $this->replaceServiceProvider("Redis", RedisServiceProvider::class); + } + + protected function registerCacheService() + { + $this->replaceServiceProvider("Cache", CacheServiceProvider::class); + } + + protected function registerFileCacheService() + { + $this->replaceServiceProvider("FileCache", FileCacheServiceProvider::class); + } + + protected function registerLoggerService() + { + $this->replaceServiceProvider("Logger", LoggerServiceProvider::class); + } + + protected function registerTwigService() + { + $this->replaceServiceProvider("Twig", TwigServiceProvider::class); + } + + protected function registerDoctrineService() + { + $this->replaceServiceProvider("Doctrine", DoctrineServiceProvider::class); + } + + protected function registerCsrfTokenService() + { + $this->replaceServiceProvider("CsrfToken", CsrfTokenServiceProvider::class); + } + + protected function registerJwtService() + { + $this->replaceServiceProvider("Jwt", JwtServiceProvider::class); + } + + protected function registerSwiftMailerService() + { + $this->replaceServiceProvider("SwiftMailer", SwiftMailerServiceProvider::class); + } + + protected function registerQueueService() + { + $this->replaceServiceProvider("Queue", QueueServiceProvider::class); + } + + // kernel listener register + + /** + * @param $listener + * @param string $action + */ + protected function registerRequestListener($listener, $action = "onRequestAction") + { + $this->replaceListener(AppEvent::REQUEST, $listener, $action); + } + + protected function registerMiddlewareListener($listener, $action = "onMiddlewareAction") + { + $this->replaceListener(AppEvent::MIDDLEWARE, $listener, $action); + } + + protected function registerResponseListener($listener, $action = "onResponseAction") + { + $this->replaceListener(AppEvent::RESPONSE, $listener, $action); + } + + protected function registerExceptionListener($listener, $action = "onExceptionAction") + { + $this->replaceListener(AppEvent::EXCEPTION, $listener, $action); + } + + protected function registerMailListener($listener, $action = "onSendMailAction") + { + $this->replaceListener(MailEvent::MAIlSEND, $listener, $action); + } + + protected function registerNotFoundListener($listener, $action = "onNotFoundPageAction") + { + $this->replaceListener(AppEvent::NOTFOUND, $listener, $action); + } } \ No newline at end of file