Skip to content

Commit

Permalink
extend event
Browse files Browse the repository at this point in the history
  • Loading branch information
hhxsv5 committed Jan 26, 2018
1 parent cbdbc73 commit 40b21a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ 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()]);
});
```

- `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()]);
});
```

Expand Down
2 changes: 1 addition & 1 deletion src/LaravelS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 40b21a8

Please sign in to comment.