From a86be3c52696dc02a7c08c0a782b46f67518f21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 19 Jul 2017 16:12:26 +0200 Subject: [PATCH] Forward-compatibility with future Socket v1.0 and Socket v0.8 Socket v0.8 only contains some minor breaking changes, which can be circumvented by ignoring URI schemes here. Future Socket v1.0 will not contain any BC breaks, so it's actually compatible with the last release. --- composer.json | 2 +- src/Ratchet/Server/IoServer.php | 5 +++-- tests/unit/Server/IoServerTest.php | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index a070212..993e4c7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ } , "require": { "php": ">=5.3.9" - , "react/socket": "^0.7 || ^0.6 || ^0.5" + , "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5" , "guzzle/http": "^3.6" , "symfony/http-foundation": "^2.2|^3.0" , "symfony/routing": "^2.2|^3.0" diff --git a/src/Ratchet/Server/IoServer.php b/src/Ratchet/Server/IoServer.php index 4031638..3fcf76c 100644 --- a/src/Ratchet/Server/IoServer.php +++ b/src/Ratchet/Server/IoServer.php @@ -89,10 +89,11 @@ class IoServer { */ public function handleConnect($conn) { $conn->decor = new IoConnection($conn); - $conn->decor->resourceId = (int)$conn->stream; + + $uri = $conn->getRemoteAddress(); $conn->decor->remoteAddress = trim( - parse_url('tcp://' . $conn->getRemoteAddress(), PHP_URL_HOST), + parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST), '[]' ); diff --git a/tests/unit/Server/IoServerTest.php b/tests/unit/Server/IoServerTest.php index ec54b5d..284fbde 100644 --- a/tests/unit/Server/IoServerTest.php +++ b/tests/unit/Server/IoServerTest.php @@ -22,7 +22,8 @@ class IoServerTest extends \PHPUnit_Framework_TestCase { $loop = new StreamSelectLoop; $this->reactor = new Server(0, $loop); - $this->port = parse_url('tcp://' . $this->reactor->getAddress(), PHP_URL_PORT); + $uri = $this->reactor->getAddress(); + $this->port = parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_PORT); $this->server = new IoServer($this->app, $this->reactor, $loop); }