| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace React\EventLoop;
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* The `Factory` class exists as a convenient way to pick the best available event loop implementation.
|
|
|
7 |
*/
|
|
|
8 |
final class Factory
|
|
|
9 |
{
|
|
|
10 |
/**
|
|
|
11 |
* Creates a new event loop instance
|
|
|
12 |
*
|
|
|
13 |
* ```php
|
|
|
14 |
* $loop = React\EventLoop\Factory::create();
|
|
|
15 |
* ```
|
|
|
16 |
*
|
|
|
17 |
* This method always returns an instance implementing `LoopInterface`,
|
|
|
18 |
* the actual event loop implementation is an implementation detail.
|
|
|
19 |
*
|
|
|
20 |
* This method should usually only be called once at the beginning of the program.
|
|
|
21 |
*
|
|
|
22 |
* @return LoopInterface
|
|
|
23 |
*/
|
|
|
24 |
public static function create()
|
|
|
25 |
{
|
|
|
26 |
// @codeCoverageIgnoreStart
|
|
|
27 |
if (\function_exists('uv_loop_new')) {
|
|
|
28 |
// only use ext-uv on PHP 7
|
|
|
29 |
return new ExtUvLoop();
|
|
|
30 |
} elseif (\class_exists('libev\EventLoop', false)) {
|
|
|
31 |
return new ExtLibevLoop();
|
|
|
32 |
} elseif (\class_exists('EvLoop', false)) {
|
|
|
33 |
return new ExtEvLoop();
|
|
|
34 |
} elseif (\class_exists('EventBase', false)) {
|
|
|
35 |
return new ExtEventLoop();
|
|
|
36 |
} elseif (\function_exists('event_base_new') && \PHP_MAJOR_VERSION === 5) {
|
|
|
37 |
// only use ext-libevent on PHP 5 for now
|
|
|
38 |
return new ExtLibeventLoop();
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return new StreamSelectLoop();
|
|
|
42 |
// @codeCoverageIgnoreEnd
|
|
|
43 |
}
|
|
|
44 |
}
|