|
2 | 2 |
|
3 | 3 | namespace Clue\React\Ssdp; |
4 | 4 |
|
5 | | -use React\EventLoop\LoopInterface; |
6 | 5 | use Clue\React\Multicast\Factory as MulticastFactory; |
| 6 | +use React\EventLoop\Loop; |
| 7 | +use React\EventLoop\LoopInterface; |
7 | 8 | use React\Promise\Deferred; |
8 | 9 | use RuntimeException; |
9 | 10 |
|
10 | 11 | class Client |
11 | 12 | { |
12 | 13 | const ADDRESS = '239.255.255.250:1900'; |
13 | 14 |
|
| 15 | + /** @var LoopInterface */ |
14 | 16 | private $loop; |
| 17 | + |
| 18 | + /** @var MulticastFactory */ |
15 | 19 | private $multicast; |
16 | 20 |
|
17 | | - public function __construct(LoopInterface $loop, MulticastFactory $multicast = null) |
| 21 | + /** |
| 22 | + * This class takes an optional `LoopInterface|null $loop` parameter that can be used to |
| 23 | + * pass the event loop instance to use for this object. You can use a `null` value |
| 24 | + * here in order to use the [default loop](https://github.com/reactphp/event-loop#loop). |
| 25 | + * This value SHOULD NOT be given unless you're sure you want to explicitly use a |
| 26 | + * given event loop instance. |
| 27 | + * |
| 28 | + * @param ?LoopInterface $loop |
| 29 | + * @param ?MulticastFactory $multicast |
| 30 | + */ |
| 31 | + public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null) |
18 | 32 | { |
19 | | - if ($multicast === null) { |
20 | | - $multicast = new MulticastFactory($loop); |
21 | | - } |
22 | | - $this->loop = $loop; |
23 | | - $this->multicast = $multicast; |
| 33 | + $this->loop = $loop ?: Loop::get(); |
| 34 | + $this->multicast = $multicast ?: new MulticastFactory($this->loop); |
24 | 35 | } |
25 | 36 |
|
26 | 37 | public function search($searchTarget = 'ssdp:all', $mx = 2) |
|
0 commit comments