From d5e85551f80bb7736fbbe63ec5e99ec1818c0e5a Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 1 Sep 2025 23:25:44 +0200 Subject: [PATCH] Allow usage of ratchet/rfc6455 0.4+ ratchet/rfc6455 as a new required param in the constructor of ServerNegotiator which is breaking the code. As this project still supports very old php versions we need to keep support for 0.3 but also include support for 0.4. Reflection is used to check for the correct version. The option of using composer's new version checks is not possible as the older versions of composer do not have this class. --- composer.json | 2 +- src/Ratchet/WebSocket/WsServer.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1c078970..3b9ebf1e 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ } , "require": { "php": ">=5.4.2" - , "ratchet/rfc6455": "^0.3.1" + , "ratchet/rfc6455": "^0.4.0 | ^0.3.1" , "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5" , "react/event-loop": "^1.0 || ^0.5 || ^0.4" , "guzzlehttp/psr7": "^1.7|^2.0" diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 5a015d83..88c56348 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -14,6 +14,7 @@ use Ratchet\RFC6455\Handshake\ServerNegotiator; use Ratchet\RFC6455\Handshake\RequestVerifier; use React\EventLoop\LoopInterface; +use GuzzleHttp\Psr7\HttpFactory; use GuzzleHttp\Psr7\Message; /** @@ -86,7 +87,13 @@ public function __construct(ComponentInterface $component) { $this->connections = new \SplObjectStorage; $this->closeFrameChecker = new CloseFrameChecker; - $this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier); + + if (self::isRFC6455v03()) { + $this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier); + } else { + $this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier, new HttpFactory); + } + $this->handshakeNegotiator->setStrictSubProtocolCheck(true); if ($component instanceof WsServerInterface) { @@ -101,6 +108,11 @@ public function __construct(ComponentInterface $component) { }; } + private static function isRFC6455v03() { + $reflection = new \ReflectionClass('Ratchet\RFC6455\Handshake\ServerNegotiator'); + return $reflection->getMethod('__construct')->getNumberOfRequiredParameters() === 1; + } + /** * {@inheritdoc} */