From 96a93e93b5a97a6aefa6b6dfa5e2b346c9fb4af9 Mon Sep 17 00:00:00 2001 From: Jeroen van Meeuwen Date: Tue, 12 Jan 2021 09:59:04 +0100 Subject: [PATCH] Remove public path -> document root change --- config/swoole_http.php | 2 +- src/Server/Manager.php | 4 ++-- src/Transformers/Request.php | 8 ++++---- tests/Server/ManagerTest.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/swoole_http.php b/config/swoole_http.php index 4eeb878f..150e680f 100644 --- a/config/swoole_http.php +++ b/config/swoole_http.php @@ -12,7 +12,7 @@ 'server' => [ 'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'), 'port' => env('SWOOLE_HTTP_PORT', '1215'), - 'document_root' => base_path('public'), + 'public_path' => base_path('public'), // Determine if to use swoole to respond request for static files 'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true), 'access_log' => env('SWOOLE_HTTP_ACCESS_LOG', false), diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 845dc234..7f13f862 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -205,11 +205,11 @@ public function onRequest($swooleRequest, $swooleResponse) $this->resetOnRequest(); $sandbox = $this->app->make(Sandbox::class); $handleStatic = $this->container->make('config')->get('swoole_http.server.handle_static_files', true); - $documentRoot = $this->container->make('config')->get('swoole_http.server.document_root', base_path('public')); + $publicPath = $this->container->make('config')->get('swoole_http.server.public_path', base_path('public')); try { // handle static file request first - if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $documentRoot)) { + if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $publicPath)) { return; } // transform swoole request to illuminate request diff --git a/src/Transformers/Request.php b/src/Transformers/Request.php index 16e4c006..791cd156 100644 --- a/src/Transformers/Request.php +++ b/src/Transformers/Request.php @@ -175,15 +175,15 @@ protected static function transformServerParameters(array $server, array $header * * @param \Swoole\Http\Request $swooleRequest * @param \Swoole\Http\Response $swooleResponse - * @param string $documentRoot + * @param string $publicPath * * @return boolean */ - public static function handleStatic($swooleRequest, $swooleResponse, string $documentRoot) + public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath) { $uri = $swooleRequest->server['request_uri'] ?? ''; $extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?'); - $fileName = @realpath($documentRoot . $uri); + $fileName = @realpath($publicPath . $uri); if (!$fileName) { return false; @@ -193,7 +193,7 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $doc return false; } - if (substr($fileName, 0, strlen($documentRoot)) != $documentRoot) { + if (substr($fileName, 0, strlen($publicPath)) != $publicPath) { return false; } diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index 2f2e5901..2f56f526 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -61,7 +61,7 @@ class ManagerTest extends TestCase 'swoole_http.tables' => [], 'swoole_http.providers' => [], 'swoole_http.resetters' => [], - 'swoole_http.server.document_root' => '/', + 'swoole_http.server.public_path' => '/', ]; public function testGetFramework()