Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix accessLog middleware in lumen
  • Loading branch information
albertcht committed Mar 6, 2019
commit 2e640940ca2e182497b6afc2bda204a064fc397d
15 changes: 10 additions & 5 deletions src/HttpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use SwooleTW\Http\Helpers\FW;
use Illuminate\Queue\QueueManager;
use Illuminate\Contracts\Http\Kernel;
use Swoole\Http\Server as HttpServer;
use Illuminate\Support\ServiceProvider;
use SwooleTW\Http\Middleware\AccessLog;
use SwooleTW\Http\Server\Facades\Server;
use Illuminate\Database\DatabaseManager;
use SwooleTW\Http\Coroutine\MySqlConnection;
Expand Down Expand Up @@ -62,11 +60,18 @@ public function register()
abstract protected function registerManager();

/**
* Boot routes.
* Boot websocket routes.
*
* @return void
*/
abstract protected function bootRoutes();
abstract protected function bootWebsocketRoutes();

/**
* Register access log middleware to container.
*
* @return void
*/
abstract protected function pushAccessLogMiddleware();

/**
* Boot the service provider.
Expand All @@ -88,7 +93,7 @@ public function boot()
}

if ($config->get('swoole_http.server.access_log')) {
$this->app->make(Kernel::class)->pushMiddleware(AccessLog::class);
$this->pushAccessLogMiddleware();
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace SwooleTW\Http;

use SwooleTW\Http\Server\Manager;
use Illuminate\Contracts\Http\Kernel;
use SwooleTW\Http\Middleware\AccessLog;

/**
* @codeCoverageIgnore
Expand All @@ -24,12 +26,23 @@ protected function registerManager()
}

/**
* Boot routes.
* Boot websocket routes.
*
* @return void
*/
protected function bootRoutes()
protected function bootWebsocketRoutes()
{
{
require __DIR__ . '/../routes/laravel_routes.php';
}

/**
* Register access log middleware to container.
*
* @return void
*/
protected function pushAccessLogMiddleware()
{
$this->app->make(Kernel::class)->pushMiddleware(AccessLog::class);
}
}
16 changes: 14 additions & 2 deletions src/LumenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SwooleTW\Http;

use SwooleTW\Http\Server\Manager;
use SwooleTW\Http\Middleware\AccessLog;

/**
* @codeCoverageIgnore
Expand All @@ -24,14 +25,15 @@ protected function registerManager()
}

/**
* Boot routes.
* Boot websocket routes.
*
* @return void
*/
protected function bootRoutes()
protected function bootWebsocketRoutes()
{
$app = $this->app;

// router only exists after lumen 5.5
if (property_exists($app, 'router')) {
$app->router->group(['namespace' => 'SwooleTW\Http\Controllers'], function ($app) {
require __DIR__ . '/../routes/lumen_routes.php';
Expand All @@ -42,4 +44,14 @@ protected function bootRoutes()
});
}
}

/**
* Register access log middleware to container.
*
* @return void
*/
protected function pushAccessLogMiddleware()
{
$this->app->middleware(AccessLog::class);
}
}