1
0
mirror of https://github.com/danog/file.git synced 2024-11-26 11:54:54 +01:00

Add isSupported() method

This commit is contained in:
Aaron Piotrowski 2018-10-28 09:36:23 -05:00
parent 04f047aec6
commit 36de5ba892
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 20 additions and 2 deletions

View File

@ -11,6 +11,14 @@ class EioDriver implements Driver
/** @var \Amp\File\Internal\EioPoll */ /** @var \Amp\File\Internal\EioPoll */
private $poll; 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() public function __construct()
{ {
$this->poll = new Internal\EioPoll; $this->poll = new Internal\EioPoll;

View File

@ -20,6 +20,16 @@ class UvDriver implements Driver
/** @var UvPoll */ /** @var UvPoll */
private $poll; 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 * @param \Amp\Loop\UvDriver $driver
*/ */

View File

@ -41,11 +41,11 @@ function driver(): Driver
{ {
$driver = Loop::get(); $driver = Loop::get();
if ($driver instanceof Loop\UvDriver) { if (UvDriver::isSupported($driver)) {
return new UvDriver($driver); return new UvDriver($driver);
} }
if (\extension_loaded("eio")) { if (EioDriver::isSupported()) {
return new EioDriver; return new EioDriver;
} }