friendship ended with social-app. php is my new best friend
1<?php
2
3namespace React\EventLoop;
4
5/**
6 * [Deprecated] The `Factory` class exists as a convenient way to pick the best available event loop implementation.
7 *
8 * @deprecated 1.2.0 See Loop instead.
9 * @see Loop
10 */
11final class Factory
12{
13 /**
14 * [Deprecated] Creates a new event loop instance
15 *
16 * ```php
17 * // deprecated
18 * $loop = React\EventLoop\Factory::create();
19 *
20 * // new
21 * $loop = React\EventLoop\Loop::get();
22 * ```
23 *
24 * This method always returns an instance implementing `LoopInterface`,
25 * the actual event loop implementation is an implementation detail.
26 *
27 * This method should usually only be called once at the beginning of the program.
28 *
29 * @deprecated 1.2.0 See Loop::get() instead.
30 * @see Loop::get()
31 *
32 * @return LoopInterface
33 */
34 public static function create()
35 {
36 $loop = self::construct();
37
38 Loop::set($loop);
39
40 return $loop;
41 }
42
43 /**
44 * @internal
45 * @return LoopInterface
46 */
47 private static function construct()
48 {
49 // @codeCoverageIgnoreStart
50 if (\function_exists('uv_loop_new')) {
51 // only use ext-uv on PHP 7
52 return new ExtUvLoop();
53 }
54
55 if (\class_exists('libev\EventLoop', false)) {
56 return new ExtLibevLoop();
57 }
58
59 if (\class_exists('EvLoop', false)) {
60 return new ExtEvLoop();
61 }
62
63 if (\class_exists('EventBase', false)) {
64 return new ExtEventLoop();
65 }
66
67 if (\function_exists('event_base_new') && \PHP_MAJOR_VERSION === 5) {
68 // only use ext-libevent on PHP 5 for now
69 return new ExtLibeventLoop();
70 }
71
72 return new StreamSelectLoop();
73 // @codeCoverageIgnoreEnd
74 }
75}