Skip to content

Commit 36de5ba

Browse files
committed
Add isSupported() method
1 parent 04f047a commit 36de5ba

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/EioDriver.php

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ class EioDriver implements Driver
1111
/** @var \Amp\File\Internal\EioPoll */
1212
private $poll;
1313

14+
/**
15+
* @return bool Determines if this driver can be used based on the environment.
16+
*/
17+
public static function isSupported(): bool
18+
{
19+
return \extension_loaded('eio');
20+
}
21+
1422
public function __construct()
1523
{
1624
$this->poll = new Internal\EioPoll;

lib/UvDriver.php

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class UvDriver implements Driver
2020
/** @var UvPoll */
2121
private $poll;
2222

23+
/**
24+
* @param \Amp\Loop\Driver The currently active loop driver.
25+
*
26+
* @return bool Determines if this driver can be used based on the environment.
27+
*/
28+
public static function isSupported(Loop\Driver $driver): bool
29+
{
30+
return $driver instanceof Loop\UvDriver;
31+
}
32+
2333
/**
2434
* @param \Amp\Loop\UvDriver $driver
2535
*/

lib/functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ function driver(): Driver
4141
{
4242
$driver = Loop::get();
4343

44-
if ($driver instanceof Loop\UvDriver) {
44+
if (UvDriver::isSupported($driver)) {
4545
return new UvDriver($driver);
4646
}
4747

48-
if (\extension_loaded("eio")) {
48+
if (EioDriver::isSupported()) {
4949
return new EioDriver;
5050
}
5151

0 commit comments

Comments
 (0)