Skip to content

Commit dca08ec

Browse files
committed
Remove event loop adapter from public API
1 parent 498c431 commit dca08ec

File tree

12 files changed

+29
-29
lines changed

12 files changed

+29
-29
lines changed

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ composer require revolt/event-loop-adapter-react
1414

1515
## Usage
1616

17-
Everywhere where a ReactPHP library requires an instance of `LoopInterface`, you just pass `ReactAdapter::get()` to run
18-
the ReactPHP library on the [Revolt event loop](https://revolt.run/).
17+
Everywhere where a ReactPHP library requires an instance of `LoopInterface`, you just pass `Loop::get()` as normal.
18+
We automatically set up everything to run the ReactPHP library on the [Revolt event loop](https://revolt.run/).
1919

2020
```php
2121
<?php
2222

2323
require 'vendor/autoload.php';
2424

25+
use React\EventLoop\Loop;
2526
use Revolt\EventLoop;
26-
use Revolt\EventLoop\Adapter\React\RevoltLoop;
2727

2828
$app = function ($request, $response) {
2929
$response->writeHead(200, array('Content-Type' => 'text/plain'));
3030
$response->end("Hello World\n");
3131
};
3232

33-
$socket = new React\Socket\Server(RevoltLoop::get());
34-
$http = new React\Http\Server($socket, RevoltLoop::get());
33+
$socket = new React\Socket\Server(Loop::get());
34+
$http = new React\Http\Server($socket, Loop::get());
3535

3636
$http->on('request', $app);
3737
echo "Server running at http://127.0.0.1:1337\n";
@@ -40,10 +40,3 @@ $socket->listen(1337);
4040

4141
EventLoop::run();
4242
```
43-
44-
You can also use the adapter to run ReactPHP apps on a specific [Revolt event loop](https://revolt.run/) implementation
45-
without relying on Revolt's global event loop.
46-
47-
```php
48-
$loop = new Revolt\EventLoop\Adapter\React\RevoltLoop((new Revolt\EventLoop\DriverFactory)->create());
49-
```

etc/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace React\EventLoop;
44

5-
use Revolt\EventLoop\Adapter\React\RevoltLoop;
5+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
66

77
(static function () {
88
$constName = 'REVOLT_ADAPTER_REACT_DISABLE_FACTORY_OVERRIDE';
@@ -23,7 +23,7 @@ public static function create(): LoopInterface
2323
{
2424
throw new \Error(
2525
__METHOD__ . '() has been overridden by revolt/event-loop-adapter-react to prevent you from accidentally creating two event loop instances. ' .
26-
'Use ' . RevoltLoop::class . '::get() instead of React\EventLoop\Factory::create() to ensure everything is running on the same event loop. ' .
26+
'Use ' . EventLoopAdapter::class . '::get() instead of React\EventLoop\Factory::create() to ensure everything is running on the same event loop. ' .
2727
'You may set a constant or environment variable named REVOLT_ADAPTER_REACT_DISABLE_FACTORY_OVERRIDE to disable this protection or open an issue at https://github.com/revoltphp/event-loop-adapter-react if you\'re unsure on the right way forward.'
2828
);
2929
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace Revolt\EventLoop\Adapter\React;
3+
namespace Revolt\EventLoop\Adapter\React\Internal;
44

55
use React\EventLoop\LoopInterface;
66
use React\EventLoop\TimerInterface;
77
use Revolt\EventLoop;
8-
use Revolt\EventLoop\Adapter\React\Internal\Timer;
98
use Revolt\EventLoop\Driver;
109

11-
final class RevoltLoop implements LoopInterface
10+
/** @internal */
11+
final class EventLoopAdapter implements LoopInterface
1212
{
1313
private static \WeakMap $instances;
1414

src/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

33
use React\EventLoop\Loop;
4-
use Revolt\EventLoop\Adapter\React\RevoltLoop;
4+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
55

66
/**
77
* @psalm-suppress InternalMethod
88
*/
9-
Loop::set(RevoltLoop::get());
9+
Loop::set(EventLoopAdapter::get());

test/EvTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use React\EventLoop\LoopInterface;
66
use Revolt\EventLoop;
7+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
78

89
class EvTest extends Test
910
{
@@ -14,6 +15,6 @@ public function createLoop(): LoopInterface
1415
}
1516

1617
EventLoop::setDriver(new EventLoop\Driver\EvDriver());
17-
return RevoltLoop::get();
18+
return EventLoopAdapter::get();
1819
}
1920
}

test/EvTimerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use React\EventLoop\LoopInterface;
66
use Revolt\EventLoop;
7+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
78

89
class EvTimerTest extends TimerTest
910
{
@@ -14,6 +15,6 @@ public function createLoop(): LoopInterface
1415
}
1516

1617
EventLoop::setDriver(new EventLoop\Driver\EvDriver());
17-
return RevoltLoop::get();
18+
return EventLoopAdapter::get();
1819
}
1920
}

test/EventTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function createLoop(): LoopInterface
1414
}
1515

1616
EventLoop::setDriver(new EventLoop\Driver\EventDriver());
17-
return EventLoop\Adapter\React\RevoltLoop::get();
17+
return Internal\EventLoopAdapter::get();
1818
}
1919
}

test/EventTimerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use React\EventLoop\LoopInterface;
66
use Revolt\EventLoop;
7+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
78

89
class EventTimerTest extends TimerTest
910
{
@@ -14,6 +15,6 @@ public function createLoop(): LoopInterface
1415
}
1516

1617
EventLoop::setDriver(new EventLoop\Driver\EventDriver());
17-
return RevoltLoop::get();
18+
return EventLoopAdapter::get();
1819
}
1920
}

test/Test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use React\EventLoop\LoopInterface;
66
use React\Tests\EventLoop\AbstractLoopTest;
77
use Revolt\EventLoop;
8+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
89
use Revolt\EventLoop\Adapter\React\Internal\Timer;
910
use Revolt\EventLoop\Driver;
1011
use Revolt\EventLoop\Driver\StreamSelectDriver;
@@ -15,7 +16,7 @@ class Test extends AbstractLoopTest
1516
public function createLoop(): LoopInterface
1617
{
1718
EventLoop::setDriver(new StreamSelectDriver());
18-
return RevoltLoop::get();
19+
return EventLoopAdapter::get();
1920
}
2021

2122
public function testIgnoreRemovedCallback()
@@ -58,7 +59,7 @@ public function testCancelTimerReturnsIfNotSet()
5859
$driver = $this->createMock(EventLoop\Driver::class);
5960
$driver->expects($this->never())->method($this->anything());
6061

61-
$loop = new RevoltLoop($driver);
62+
$loop = new EventLoopAdapter($driver);
6263
$loop->cancelTimer($timer);
6364
}
6465

@@ -74,7 +75,7 @@ public function testAddSignalUnsupportedFeatureExceptionIsCast()
7475
$driver = $this->createMock(Driver::class);
7576
$driver->method('onSignal')->with($signal, $listener)->willThrowException($exception);
7677

77-
$loop = new RevoltLoop($driver);
78+
$loop = new EventLoopAdapter($driver);
7879
$loop->addSignal($signal, $listener);
7980
}
8081
}

test/TimerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
use React\EventLoop\LoopInterface;
66
use React\Tests\EventLoop\Timer\AbstractTimerTest;
77
use Revolt\EventLoop;
8+
use Revolt\EventLoop\Adapter\React\Internal\EventLoopAdapter;
89

910
class TimerTest extends AbstractTimerTest
1011
{
1112
public function createLoop(): LoopInterface
1213
{
1314
EventLoop::setDriver(new EventLoop\Driver\StreamSelectDriver());
14-
return RevoltLoop::get();
15+
return EventLoopAdapter::get();
1516
}
1617
}

0 commit comments

Comments
 (0)