From 40b21a825b7ed4fb0cf602c2e53649d6eef485ae Mon Sep 17 00:00:00 2001 From: XieBiao Date: Fri, 26 Jan 2018 11:48:11 +0800 Subject: [PATCH] extend event --- README.md | 6 ++++-- src/LaravelS.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2de48867..2c22717c 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ php artisan laravels {start|stop|restart|reload} ```PHP // Edit file `app/Providers/EventServiceProvider.php`, add the following code into method `boot` \Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req) { + //$req->offsetSet('name', 'hhxsv5');// Change request \Log::info('Received Request', [$req->getRequestUri(), $req->all()]); }); ``` @@ -63,8 +64,9 @@ php artisan laravels {start|stop|restart|reload} - `laravels.generated_response` After Laravel's Kernel handled the request, before LaravelS parses `Illuminate\Http\Response` to `swoole_http_response`. ```PHP -\Event::listen('laravels.generated_response', function (\Illuminate\Http\Response $rsp) { - \Log::info('Generated Response', [$rsp->getContent()]); +\Event::listen('laravels.generated_response', function (\Illuminate\Http\Request $req, \Illuminate\Http\Response $rsp) { + $rsp->header('name', 'hhxsv5');// Change response + \Log::info('Generated Response', [$req->getRequestUri(), $rsp->getContent()]); }); ``` diff --git a/src/LaravelS.php b/src/LaravelS.php index f89a5450..943b86fd 100644 --- a/src/LaravelS.php +++ b/src/LaravelS.php @@ -75,7 +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.generated_response', [$laravelResponse]); + $this->laravel->fireEvent('laravels.generated_response', [$laravelRequest, $laravelResponse]); (new DynamicResponse($swooleResponse, $laravelResponse))->send(); return true; }