1
0
mirror of https://github.com/danog/amp.git synced 2024-12-14 18:37:30 +01:00
amp/lib/ReactorFactory.php

31 lines
893 B
PHP
Raw Normal View History

2013-08-05 22:05:08 +02:00
<?php
2014-09-23 04:38:32 +02:00
namespace Amp;
2013-08-05 22:05:08 +02:00
class ReactorFactory {
2014-08-01 21:37:02 +02:00
private static $reactor;
2013-08-05 22:05:08 +02:00
2014-08-01 21:37:02 +02:00
/**
* This method is deprecated. New code should use Amp\getReactor() instead.
2014-08-01 21:37:02 +02:00
*/
public static function select(callable $factory = null) {
trigger_error(
'Amp\\ReactorFactory is deprecated and scheduled for removal. ' .
'Please update code to use the Amp\\getReactor() function instead.',
E_USER_DEPRECATED
);
2014-08-01 21:37:02 +02:00
if (self::$reactor) {
return self::$reactor;
} elseif ($factory) {
2014-08-02 07:09:07 +02:00
return self::$reactor = $factory();
2014-08-01 21:37:02 +02:00
} elseif (extension_loaded('uv')) {
2014-08-02 07:09:07 +02:00
return self::$reactor = new UvReactor;
2014-06-11 18:21:46 +02:00
} elseif (extension_loaded('libevent')) {
2014-08-02 07:09:07 +02:00
return self::$reactor = new LibeventReactor;
2013-08-05 22:05:08 +02:00
} else {
2014-08-02 07:09:07 +02:00
return self::$reactor = new NativeReactor;
2013-08-05 22:05:08 +02:00
}
}
}