From c1f078775f291d4b20d317650dd07b3cff784b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C5=82as=20Piotr?= Date: Mon, 9 Jun 2025 20:26:22 +0200 Subject: [PATCH] Move runtime classes to Standalone namespace and update references --- .gitignore | 1 + README.md | 2 +- example/bin/start_server.sh | 2 +- src/Middleware/StaticFileMiddleware.php | 2 +- src/{ => Standalone}/Runner.php | 3 ++- src/{ => Standalone}/Runtime.php | 2 +- src/{ => Standalone}/ServerFactory.php | 2 +- tests/RunnerTest.php | 4 ++-- tests/RuntimeTest.php | 4 ++-- tests/ServerFactoryTest.php | 2 +- 10 files changed, 13 insertions(+), 11 deletions(-) rename src/{ => Standalone}/Runner.php (84%) rename src/{ => Standalone}/Runtime.php (92%) rename src/{ => Standalone}/ServerFactory.php (98%) diff --git a/.gitignore b/.gitignore index 63164d8..3600683 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ composer.lock /.idea/vcs.xml /.idea/symfony2.xml /.phpunit.result.cache +/var diff --git a/README.md b/README.md index 953df99..f4fdd95 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Define the environment variable `APP_RUNTIME` for your application. You can also `APP_ENV` and `APP_DEBGU` variables to define runtime environment. ``` - APP_ENV=prod APP_DEBUG=1 APP_RUNTIME=CrazyGoat\\ReactPHPRuntime\\Runtime php ./public/index.ph + APP_ENV=prod APP_DEBUG=1 APP_RUNTIME=CrazyGoat\\ReactPHPRuntime\\Standalone\\Runtime php ./public/index.ph ``` ## Server options diff --git a/example/bin/start_server.sh b/example/bin/start_server.sh index 3bd0122..dc29ac0 100755 --- a/example/bin/start_server.sh +++ b/example/bin/start_server.sh @@ -5,7 +5,7 @@ export REACT_HOST=0.0.0.0 export REACT_PORT=8080 export APP_ENV=prod export APP_DEBUG=0 -export APP_RUNTIME=CrazyGoat\\ReactPHPRuntime\\Runtime +export APP_RUNTIME=CrazyGoat\\ReactPHPRuntime\\Standalone\\Runtime export REACT_ROOT_DIR echo "Starting http server, visit http://$REACT_HOST:$REACT_PORT" diff --git a/src/Middleware/StaticFileMiddleware.php b/src/Middleware/StaticFileMiddleware.php index 969e1f6..88a8359 100644 --- a/src/Middleware/StaticFileMiddleware.php +++ b/src/Middleware/StaticFileMiddleware.php @@ -34,7 +34,7 @@ public function __invoke(ServerRequestInterface $request, callable $next): Promi if (!is_file($fileCandidate) || !is_readable($fileCandidate)) { return $this->returnResponse($next($request)); } - echo "$fileCandidate" . PHP_EOL; + return new Response( StatusCodeInterface::STATUS_OK, [ diff --git a/src/Runner.php b/src/Standalone/Runner.php similarity index 84% rename from src/Runner.php rename to src/Standalone/Runner.php index 420466e..d5814d9 100644 --- a/src/Runner.php +++ b/src/Standalone/Runner.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace CrazyGoat\ReactPHPRuntime; +namespace CrazyGoat\ReactPHPRuntime\Standalone; +use CrazyGoat\ReactPHPRuntime\RequestHandler; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Runtime\RunnerInterface; diff --git a/src/Runtime.php b/src/Standalone/Runtime.php similarity index 92% rename from src/Runtime.php rename to src/Standalone/Runtime.php index 46cc12e..afa7bf6 100644 --- a/src/Runtime.php +++ b/src/Standalone/Runtime.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace CrazyGoat\ReactPHPRuntime; +namespace CrazyGoat\ReactPHPRuntime\Standalone; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Runtime\GenericRuntime; diff --git a/src/ServerFactory.php b/src/Standalone/ServerFactory.php similarity index 98% rename from src/ServerFactory.php rename to src/Standalone/ServerFactory.php index fb8d38d..26dc0a8 100644 --- a/src/ServerFactory.php +++ b/src/Standalone/ServerFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace CrazyGoat\ReactPHPRuntime; +namespace CrazyGoat\ReactPHPRuntime\Standalone; use CrazyGoat\ReactPHPRuntime\Metrics\BasicMetric; use CrazyGoat\ReactPHPRuntime\Metrics\Formatter\TextMetricsFormatter; diff --git a/tests/RunnerTest.php b/tests/RunnerTest.php index dcf1b7f..4b79140 100644 --- a/tests/RunnerTest.php +++ b/tests/RunnerTest.php @@ -4,8 +4,8 @@ namespace CrazyGoat\ReactPHPRuntime\Tests; -use CrazyGoat\ReactPHPRuntime\Runner; -use CrazyGoat\ReactPHPRuntime\ServerFactory; +use CrazyGoat\ReactPHPRuntime\Standalone\Runner; +use CrazyGoat\ReactPHPRuntime\Standalone\ServerFactory; use PHPUnit\Framework\TestCase; use React\EventLoop\Loop; use React\EventLoop\LoopInterface; diff --git a/tests/RuntimeTest.php b/tests/RuntimeTest.php index 9ec47eb..51b960e 100644 --- a/tests/RuntimeTest.php +++ b/tests/RuntimeTest.php @@ -4,8 +4,8 @@ namespace CrazyGoat\ReactPHPRuntime\Tests; -use CrazyGoat\ReactPHPRuntime\Runner; -use CrazyGoat\ReactPHPRuntime\Runtime; +use CrazyGoat\ReactPHPRuntime\Standalone\Runner; +use CrazyGoat\ReactPHPRuntime\Standalone\Runtime; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\KernelInterface; diff --git a/tests/ServerFactoryTest.php b/tests/ServerFactoryTest.php index c0f7ed2..fd5402a 100644 --- a/tests/ServerFactoryTest.php +++ b/tests/ServerFactoryTest.php @@ -4,7 +4,7 @@ namespace CrazyGoat\ReactPHPRuntime\Tests; -use CrazyGoat\ReactPHPRuntime\ServerFactory; +use CrazyGoat\ReactPHPRuntime\Standalone\ServerFactory; use PHPUnit\Framework\TestCase; use Psr\Http\Server\RequestHandlerInterface; use React\EventLoop\Loop;