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} */