2017-03-10 21:31:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Loop;
|
|
|
|
|
2017-03-14 22:33:45 +01:00
|
|
|
// @codeCoverageIgnoreStart
|
2017-03-12 11:25:21 +01:00
|
|
|
class DriverFactory {
|
2017-03-10 21:31:57 +01:00
|
|
|
/**
|
|
|
|
* Creates a new loop instance and chooses the best available driver.
|
|
|
|
*
|
|
|
|
* @return Driver
|
|
|
|
*/
|
|
|
|
public function create(): Driver {
|
2017-03-12 11:25:21 +01:00
|
|
|
if (UvDriver::isSupported()) {
|
2017-03-12 11:21:44 +01:00
|
|
|
return new UvDriver;
|
2017-03-10 21:31:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 11:25:21 +01:00
|
|
|
if (EvDriver::isSupported()) {
|
2017-03-12 11:21:44 +01:00
|
|
|
return new EvDriver;
|
2017-03-10 21:31:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 11:25:21 +01:00
|
|
|
if (EventDriver::isSupported()) {
|
2017-03-12 11:21:44 +01:00
|
|
|
return new EventDriver;
|
2017-03-10 21:31:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-12 11:21:44 +01:00
|
|
|
return new NativeDriver;
|
2017-03-10 21:31:57 +01:00
|
|
|
}
|
2017-03-14 22:33:45 +01:00
|
|
|
}
|
|
|
|
// @codeCoverageIgnoreEnd
|