mirror of
https://github.com/danog/file.git
synced 2024-11-26 20:04:51 +01:00
Add isSupported() method
This commit is contained in:
parent
04f047aec6
commit
36de5ba892
@ -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;
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user