diff --git a/lib/EioDriver.php b/lib/EioDriver.php index 7d18475..1952ddb 100644 --- a/lib/EioDriver.php +++ b/lib/EioDriver.php @@ -11,6 +11,14 @@ class EioDriver implements Driver /** @var \Amp\File\Internal\EioPoll */ private $poll; + /** + * @return bool Determines if this driver can be used based on the environment. + */ + public static function isSupported(): bool + { + return \extension_loaded('eio'); + } + public function __construct() { $this->poll = new Internal\EioPoll; diff --git a/lib/UvDriver.php b/lib/UvDriver.php index 05b6205..cea4419 100644 --- a/lib/UvDriver.php +++ b/lib/UvDriver.php @@ -20,6 +20,16 @@ class UvDriver implements Driver /** @var UvPoll */ private $poll; + /** + * @param \Amp\Loop\Driver The currently active loop driver. + * + * @return bool Determines if this driver can be used based on the environment. + */ + public static function isSupported(Loop\Driver $driver): bool + { + return $driver instanceof Loop\UvDriver; + } + /** * @param \Amp\Loop\UvDriver $driver */ diff --git a/lib/functions.php b/lib/functions.php index 7ea6254..4481920 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -41,11 +41,11 @@ function driver(): Driver { $driver = Loop::get(); - if ($driver instanceof Loop\UvDriver) { + if (UvDriver::isSupported($driver)) { return new UvDriver($driver); } - if (\extension_loaded("eio")) { + if (EioDriver::isSupported()) { return new EioDriver; }