Skip to content

Commit d5e8555

Browse files
committed
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.
1 parent 2032bb0 commit d5e8555

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828
, "require": {
2929
"php": ">=5.4.2"
30-
, "ratchet/rfc6455": "^0.3.1"
30+
, "ratchet/rfc6455": "^0.4.0 | ^0.3.1"
3131
, "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5"
3232
, "react/event-loop": "^1.0 || ^0.5 || ^0.4"
3333
, "guzzlehttp/psr7": "^1.7|^2.0"

src/Ratchet/WebSocket/WsServer.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Ratchet\RFC6455\Handshake\ServerNegotiator;
1515
use Ratchet\RFC6455\Handshake\RequestVerifier;
1616
use React\EventLoop\LoopInterface;
17+
use GuzzleHttp\Psr7\HttpFactory;
1718
use GuzzleHttp\Psr7\Message;
1819

1920
/**
@@ -86,7 +87,13 @@ public function __construct(ComponentInterface $component) {
8687
$this->connections = new \SplObjectStorage;
8788

8889
$this->closeFrameChecker = new CloseFrameChecker;
89-
$this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier);
90+
91+
if (self::isRFC6455v03()) {
92+
$this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier);
93+
} else {
94+
$this->handshakeNegotiator = new ServerNegotiator(new RequestVerifier, new HttpFactory);
95+
}
96+
9097
$this->handshakeNegotiator->setStrictSubProtocolCheck(true);
9198

9299
if ($component instanceof WsServerInterface) {
@@ -101,6 +108,11 @@ public function __construct(ComponentInterface $component) {
101108
};
102109
}
103110

111+
private static function isRFC6455v03() {
112+
$reflection = new \ReflectionClass('Ratchet\RFC6455\Handshake\ServerNegotiator');
113+
return $reflection->getMethod('__construct')->getNumberOfRequiredParameters() === 1;
114+
}
115+
104116
/**
105117
* {@inheritdoc}
106118
*/

0 commit comments

Comments
 (0)