From 5a84c8336ea97d9c77472d12e3d22080acfc88eb Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Fri, 13 May 2016 23:41:54 +0200 Subject: [PATCH] Add Loop::supports to check for optional features --- src/Loop.php | 12 ++++++++++++ src/LoopDriver.php | 16 ++++++++++++++++ src/UnsupportedFeatureException.php | 9 +++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/UnsupportedFeatureException.php diff --git a/src/Loop.php b/src/Loop.php index 059f2b9..ac8ae49 100644 --- a/src/Loop.php +++ b/src/Loop.php @@ -210,6 +210,18 @@ final class Loop self::get()->unreference($eventIdentifier); } + /** + * Check whether an optional feature is supported by the current event loop + * driver. + * + * @param int $feature Loop::FEATURE_* constant + * + * @return bool + */ + public static function supports($feature) { + return self::get()->supports($feature); + } + /** * Disable construction as this is a static class. */ diff --git a/src/LoopDriver.php b/src/LoopDriver.php index 1d800d8..0ab913a 100644 --- a/src/LoopDriver.php +++ b/src/LoopDriver.php @@ -4,6 +4,8 @@ namespace Interop\Async\EventLoop; interface LoopDriver { + const FEATURE_SIGNAL_HANDLING = 0b001; + /** * Start the event loop. * @@ -135,4 +137,18 @@ interface LoopDriver * @return void */ public function unreference($eventIdentifier); + + /** + * Check whether an optional features is supported by this implementation + * and system. + * + * Example: If the implementation can handle signals using PCNTL, but the + * PCNTL extension is not available, the feature MUST NOT be marked as + * supported. + * + * @param int $feature FEATURE constant + * + * @return bool + */ + public function supports($feature); } diff --git a/src/UnsupportedFeatureException.php b/src/UnsupportedFeatureException.php new file mode 100644 index 0000000..c4ee1b8 --- /dev/null +++ b/src/UnsupportedFeatureException.php @@ -0,0 +1,9 @@ +