Skip to content

Commit

Permalink
update event name
Browse files Browse the repository at this point in the history
  • Loading branch information
hhxsv5 committed Jan 26, 2018
1 parent 9e8c212 commit cbdbc73
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Speed up Laravel/Lumen by Swoole, 'S' means Swoole, Speed, High performance.

## Install

1.Require package
1.Require package via Composer([packagist](https://packagist.org/packages/hhxsv5/laravel-s))
```Bash
composer require "hhxsv5/laravel-s:~1.0" -vvv
```
Expand All @@ -49,6 +49,25 @@ php artisan vendor:publish --provider="Hhxsv5\LaravelS\Illuminate\LaravelSServic
php artisan laravels {start|stop|restart|reload}
```

## Listen Events

- `laravels.received_request` After LaravelS parsed `swoole_http_request` to `Illuminate\Http\Request`, before Laravel's Kernel handles this request.

```PHP
// Edit file `app/Providers/EventServiceProvider.php`, add the following code into method `boot`
\Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req) {
\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()]);
});
```

## Important Notices

- `global`, `static` variables which you declared are need to destroy(reset) manually.
Expand Down
4 changes: 2 additions & 2 deletions src/LaravelS.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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->laravel->fireEvent('laravels.received_request', [$laravelRequest]);
$this->handleDynamicResource($laravelRequest, $response);
}

Expand All @@ -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.response', [$laravelResponse]);
$this->laravel->fireEvent('laravels.generated_response', [$laravelResponse]);
(new DynamicResponse($swooleResponse, $laravelResponse))->send();
return true;
}
Expand Down

0 comments on commit cbdbc73

Please sign in to comment.