From 9e8c212944b318fc14c2dfafb5a145e97cc07884 Mon Sep 17 00:00:00 2001 From: XieBiao Date: Thu, 25 Jan 2018 19:16:26 +0800 Subject: [PATCH] support event --- src/Illuminate/Laravel.php | 5 +++++ src/LaravelS.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Illuminate/Laravel.php b/src/Illuminate/Laravel.php index 6bfd68f7..d06acc22 100644 --- a/src/Illuminate/Laravel.php +++ b/src/Illuminate/Laravel.php @@ -134,4 +134,9 @@ protected function clean(Request $request) //... } + + public function fireEvent($name, array $params = []) + { + $this->app->events->fire($name, $params); + } } \ No newline at end of file diff --git a/src/LaravelS.php b/src/LaravelS.php index 835ee1e6..839cf02f 100644 --- a/src/LaravelS.php +++ b/src/LaravelS.php @@ -54,6 +54,7 @@ public function onRequest(\swoole_http_request $request, \swoole_http_response $ $laravelRequest = (new Request($request))->toIlluminateRequest(); $success = $this->handleStaticResource($laravelRequest, $response); if (!$success) { + $this->laravel->fireEvent('laravels.request', [$laravelRequest]); $this->handleDynamicResource($laravelRequest, $response); } @@ -74,6 +75,7 @@ protected function handleStaticResource(IlluminateRequest $laravelRequest, \swoo protected function handleDynamicResource(IlluminateRequest $laravelRequest, \swoole_http_response $swooleResponse) { $laravelResponse = $this->laravel->handleDynamic($laravelRequest); + $this->laravel->fireEvent('laravels.response', [$laravelResponse]); (new DynamicResponse($swooleResponse, $laravelResponse))->send(); return true; }