Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"php": ">=5.4.2"
, "ratchet/rfc6455": "^0.3.1"
, "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5"
, "react/event-loop": ">=0.4"
, "react/event-loop": "^1.0 || ^0.5 || ^0.4"
, "guzzlehttp/psr7": "^1.7|^2.0"
, "symfony/http-foundation": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0"
, "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0"
Expand Down
6 changes: 4 additions & 2 deletions src/Ratchet/App.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Ratchet;
use React\EventLoop\Factory as LegacyLoopFactory;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor;
use React\Socket\SecureServer as SecureReactor;
use Ratchet\Http\HttpServerInterface;
Expand Down Expand Up @@ -72,7 +73,8 @@ public function __construct($httpHost = 'localhost', $port = 8080, $address = '1
}

if (null === $loop) {
$loop = LoopFactory::create();
// prefer default Loop (reactphp/event-loop v1.2+) over legacy \React\EventLoop\Factory
$loop = class_exists('React\EventLoop\Loop') ? Loop::get() : LegacyLoopFactory::create();
}

$this->httpHost = $httpHost;
Expand Down
9 changes: 6 additions & 3 deletions src/Ratchet/Server/IoServer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Ratchet\Server;
use Ratchet\MessageComponentInterface;
use React\EventLoop\Factory as LegacyLoopFactory;
use React\EventLoop\Loop;
use React\EventLoop\LoopInterface;
use React\Socket\ConnectionInterface as SocketConnection;
use React\Socket\ServerInterface;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Server as Reactor;
use React\Socket\SecureServer as SecureReactor;

Expand All @@ -14,7 +15,7 @@
*/
class IoServer {
/**
* @var \React\EventLoop\LoopInterface
* @var ?\React\EventLoop\LoopInterface
*/
public $loop;

Expand Down Expand Up @@ -60,7 +61,9 @@ public function __construct(MessageComponentInterface $app, ServerInterface $soc
* @return IoServer
*/
public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') {
$loop = LoopFactory::create();
// prefer default Loop (reactphp/event-loop v1.2+) over legacy \React\EventLoop\Factory
$loop = class_exists('React\EventLoop\Loop') ? Loop::get() : LegacyLoopFactory::create();

$socket = new Reactor($address . ':' . $port, $loop);

return new static($component, $socket, $loop);
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Server/IoServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ public function testOnClose() {
}

public function testFactory() {
$this->assertInstanceOf('Ratchet\\Server\\IoServer', IoServer::factory($this->app, 0));
$server = IoServer::factory($this->app, 0);
$server->socket->close();

$this->assertInstanceOf('Ratchet\\Server\\IoServer', $server);
}

public function testNoLoopProvidedError() {
Expand Down