|
5 | 5 | use Clue\React\SQLite\Io\LazyDatabase; |
6 | 6 | use Clue\React\SQLite\Io\ProcessIoDatabase; |
7 | 7 | use React\ChildProcess\Process; |
| 8 | +use React\EventLoop\Loop; |
8 | 9 | use React\EventLoop\LoopInterface; |
9 | 10 | use React\Promise\Deferred; |
10 | 11 | use React\Stream\DuplexResourceStream; |
11 | 12 |
|
12 | 13 | class Factory |
13 | 14 | { |
| 15 | + /** @var LoopInterface */ |
14 | 16 | private $loop; |
| 17 | + |
15 | 18 | private $bin = PHP_BINARY; |
16 | 19 | private $useSocket; |
17 | 20 |
|
18 | 21 | /** |
19 | 22 | * The `Factory` is responsible for opening your [`DatabaseInterface`](#databaseinterface) instance. |
20 | | - * It also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage). |
21 | 23 | * |
22 | 24 | * ```php |
23 | | - * $loop = \React\EventLoop\Factory::create(); |
24 | | - * $factory = new Factory($loop); |
| 25 | + * $factory = new Clue\React\SQLite\Factory(); |
25 | 26 | * ``` |
26 | 27 | * |
27 | | - * @param LoopInterface $loop |
| 28 | + * This class takes an optional `LoopInterface|null $loop` parameter that can be used to |
| 29 | + * pass the event loop instance to use for this object. You can use a `null` value |
| 30 | + * here in order to use the [default loop](https://github.com/reactphp/event-loop#loop). |
| 31 | + * This value SHOULD NOT be given unless you're sure you want to explicitly use a |
| 32 | + * given event loop instance. |
| 33 | + * |
| 34 | + * @param ?LoopInterface $loop |
28 | 35 | */ |
29 | | - public function __construct(LoopInterface $loop) |
| 36 | + public function __construct(LoopInterface $loop = null) |
30 | 37 | { |
31 | | - $this->loop = $loop; |
| 38 | + $this->loop = $loop ?: Loop::get(); |
32 | 39 |
|
33 | 40 | // use socket I/O for Windows only, use faster process pipes everywhere else |
34 | 41 | $this->useSocket = DIRECTORY_SEPARATOR === '\\'; |
|
0 commit comments