Skip to content

Commit 229fb29

Browse files
authored
Merge pull request #274 from clue-labs/drop-factory
Drop deprecated `Factory`, use `Loop` instead
2 parents 862cdc4 + 10cc239 commit 229fb29

File tree

4 files changed

+28
-127
lines changed

4 files changed

+28
-127
lines changed

README.md

+5-36
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ single [`run()`](#run) call that is controlled by the user.
2626
* [Loop methods](#loop-methods)
2727
* [Loop autorun](#loop-autorun)
2828
* [get()](#get)
29-
* [~~Factory~~](#factory)
30-
* [~~create()~~](#create)
3129
* [Loop implementations](#loop-implementations)
3230
* [StreamSelectLoop](#streamselectloop)
3331
* [ExtEventLoop](#exteventloop)
@@ -111,7 +109,7 @@ beginning, reuse it throughout your program and finally run it at the end of the
111109
program like this:
112110

113111
```php
114-
$loop = React\EventLoop\Loop::get(); // or deprecated React\EventLoop\Factory::create();
112+
$loop = React\EventLoop\Loop::get();
115113

116114
$timer = $loop->addPeriodicTimer(0.1, function () {
117115
echo 'Tick' . PHP_EOL;
@@ -129,9 +127,8 @@ While the former is more concise, the latter is more explicit.
129127
In both cases, the program would perform the exact same steps.
130128

131129
1. The event loop instance is created at the beginning of the program. This is
132-
implicitly done the first time you call the [`Loop` class](#loop) or
133-
explicitly when using the deprecated [`Factory::create()` method](#create)
134-
(or manually instantiating any of the [loop implementations](#loop-implementations)).
130+
implicitly done the first time you call the [`Loop` class](#loop)
131+
(or by manually instantiating any of the [loop implementations](#loop-implementations)).
135132
2. The event loop is used directly or passed as an instance to library and
136133
application code. In this example, a periodic timer is registered with the
137134
event loop which simply outputs `Tick` every fraction of a second until another
@@ -305,33 +302,6 @@ $greeter->greet('Bob');
305302

306303
See [`LoopInterface`](#loopinterface) for more details about available methods.
307304

308-
### ~~Factory~~
309-
310-
> Deprecated since v1.2.0, see [`Loop` class](#loop) instead.
311-
312-
The deprecated `Factory` class exists as a convenient way to pick the best available
313-
[event loop implementation](#loop-implementations).
314-
315-
#### ~~create()~~
316-
317-
> Deprecated since v1.2.0, see [`Loop::get()`](#get) instead.
318-
319-
The deprecated `create(): LoopInterface` method can be used to
320-
create a new event loop instance:
321-
322-
```php
323-
// deprecated
324-
$loop = React\EventLoop\Factory::create();
325-
326-
// new
327-
$loop = React\EventLoop\Loop::get();
328-
```
329-
330-
This method always returns an instance implementing [`LoopInterface`](#loopinterface),
331-
the actual [event loop implementation](#loop-implementations) is an implementation detail.
332-
333-
This method should usually only be called once at the beginning of the program.
334-
335305
### Loop implementations
336306

337307
In addition to the [`LoopInterface`](#loopinterface), there are a number of
@@ -363,9 +333,8 @@ function and is the only implementation that works out of the box with PHP.
363333
This event loop works out of the box on PHP 5.3 through PHP 8+ and HHVM.
364334
This means that no installation is required and this library works on all
365335
platforms and supported PHP versions.
366-
Accordingly, the [`Loop` class](#loop) and the deprecated [`Factory`](#factory)
367-
will use this event loop by default if you do not install any of the event loop
368-
extensions listed below.
336+
Accordingly, the [`Loop` class](#loop) will use this event loop by default if
337+
you do not install any of the event loop extensions listed below.
369338

370339
Under the hood, it does a simple `select` system call.
371340
This system call is limited to the maximum file descriptor number of

src/Factory.php

-66
This file was deleted.

src/Loop.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function get()
3333
return self::$instance;
3434
}
3535

36-
self::$instance = $loop = Factory::create();
36+
self::$instance = $loop = self::create();
3737

3838
// Automatically run loop at end of program, unless already started or stopped explicitly.
3939
// This is tested using child processes, so coverage is actually 100%, see BinTest.
@@ -263,4 +263,26 @@ public static function stop()
263263
self::$instance->stop();
264264
}
265265
}
266+
267+
/**
268+
* @return LoopInterface
269+
*/
270+
private static function create()
271+
{
272+
// @codeCoverageIgnoreStart
273+
if (\function_exists('uv_loop_new')) {
274+
return new ExtUvLoop();
275+
}
276+
277+
if (\class_exists('EvLoop', false)) {
278+
return new ExtEvLoop();
279+
}
280+
281+
if (\class_exists('EventBase', false)) {
282+
return new ExtEventLoop();
283+
}
284+
285+
return new StreamSelectLoop();
286+
// @codeCoverageIgnoreEnd
287+
}
266288
}

tests/LoopTest.php

-24
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,10 @@
22

33
namespace React\Tests\EventLoop;
44

5-
use React\EventLoop\Factory;
65
use React\EventLoop\Loop;
76

87
final class LoopTest extends TestCase
98
{
10-
/**
11-
* @dataProvider numberOfTests
12-
*/
13-
public function testFactoryCreateSetsEventLoopOnLoopAccessor()
14-
{
15-
$factoryLoop = Factory::create();
16-
$accessorLoop = Loop::get();
17-
18-
self::assertSame($factoryLoop, $accessorLoop);
19-
}
20-
21-
/**
22-
* @dataProvider numberOfTests
23-
*/
24-
public function testCallingFactoryAfterCallingLoopGetYieldsADifferentInstanceOfTheEventLoop()
25-
{
26-
// Note that this behavior isn't wise and highly advised against. Always used Loop::get.
27-
$accessorLoop = Loop::get();
28-
$factoryLoop = Factory::create();
29-
30-
self::assertNotSame($factoryLoop, $accessorLoop);
31-
}
32-
339
/**
3410
* @dataProvider numberOfTests
3511
*/

0 commit comments

Comments
 (0)