From 781b49ee75b327dbdc4f6df25660a3482266f11f Mon Sep 17 00:00:00 2001 From: Micilini Roll Date: Sat, 9 May 2026 21:15:36 -0300 Subject: [PATCH] fix examples autoload when installed through composer --- README.md | 23 +++++++++ examples/bootstrap.php | 31 +++++++++++ examples/easy-chat/server.php | 2 +- examples/medium-chat/server.php | 2 +- examples/private-chat/server.php | 2 +- .../Examples/ExampleServerAutoloadTest.php | 51 +++++++++++++++++++ 6 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 examples/bootstrap.php create mode 100644 tests/Unit/Examples/ExampleServerAutoloadTest.php diff --git a/README.md b/README.md index 9a7204b..69120e7 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,8 @@ ws://127.0.0.1:8080 ## Running the Examples +> The example servers can be executed both from a cloned repository and from a project where the package was installed through Composer. The examples use `examples/bootstrap.php` to locate the correct Composer autoload file automatically. + Each example has two parts: 1. a WebSocket server process; @@ -164,6 +166,13 @@ Open another terminal and serve the UI: php -S 127.0.0.1:8000 -t examples/easy-chat/public ``` +If you installed the package inside another project with Composer, run: + +```bash +php vendor/micilini/php-websockets/examples/easy-chat/server.php +php -S 127.0.0.1:8000 -t vendor/micilini/php-websockets/examples/easy-chat/public +``` + Open: ```txt @@ -196,6 +205,13 @@ Open another terminal and serve the UI: php -S 127.0.0.1:8001 -t examples/medium-chat/public ``` +If you installed the package inside another project with Composer, run: + +```bash +php vendor/micilini/php-websockets/examples/medium-chat/server.php +php -S 127.0.0.1:8001 -t vendor/micilini/php-websockets/examples/medium-chat/public +``` + Open: ```txt @@ -226,6 +242,13 @@ Open another terminal and serve the UI: php -S 127.0.0.1:8002 -t examples/private-chat/public ``` +If you installed the package inside another project with Composer, run: + +```bash +php vendor/micilini/php-websockets/examples/private-chat/server.php +php -S 127.0.0.1:8002 -t vendor/micilini/php-websockets/examples/private-chat/public +``` + Open: ```txt diff --git a/examples/bootstrap.php b/examples/bootstrap.php new file mode 100644 index 0000000..8567cbb --- /dev/null +++ b/examples/bootstrap.php @@ -0,0 +1,31 @@ +