diff --git a/src/Lemon/Squeezer/Squeezer.php b/src/Lemon/Squeezer/Squeezer.php index 61fc2c3..6332bfd 100644 --- a/src/Lemon/Squeezer/Squeezer.php +++ b/src/Lemon/Squeezer/Squeezer.php @@ -68,19 +68,10 @@ public function boot(string $host, string $port) public function handleIncomming(ConnectionInterface $connection, Request $worker_request) { $path = $this->application->directory.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.$worker_request->path(); - if (file_exists($path) && !is_dir($path)) { - $extension = explode('.', $path)[1]; - $content_type = isset(self::CONTENT_TYPES[$extension]) - ? self::CONTENT_TYPES[$extension] - : 'text/plain' - ; - - $connection->send( - (new Response(200, ['Content-Type' => $content_type], file_get_contents($path))) - ); + if ($response = $this->handleFiles($path)) { + $connection->send($response); return; } - $request = $this->captureRequest($worker_request); $this->application->add(LemonRequest::class, $request); $this->application->add(Session::class, new Session($worker_request->sessionId())); @@ -99,6 +90,26 @@ public function handleIncomming(ConnectionInterface $connection, Request $worker } } + public function handleFiles(string $path): ?Response + { + if (file_exists($path) && !is_dir($path)) { + $extension = explode('.', $path)[1]; + + if ($extension === 'php') { + return null; + } + + $content_type = isset(self::CONTENT_TYPES[$extension]) + ? self::CONTENT_TYPES[$extension] + : 'text/plain' + ; + + return new Response(200, ['Content-Type' => $content_type], file_get_contents($path)); + } + + return null; + } + public function captureRequest(Request $request): LemonRequest { return new LemonRequest(