diff options
Diffstat (limited to 'vendor/react/event-loop/src/SignalsHandler.php')
-rw-r--r-- | vendor/react/event-loop/src/SignalsHandler.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/react/event-loop/src/SignalsHandler.php b/vendor/react/event-loop/src/SignalsHandler.php new file mode 100644 index 0000000..10d125d --- /dev/null +++ b/vendor/react/event-loop/src/SignalsHandler.php @@ -0,0 +1,63 @@ +<?php + +namespace React\EventLoop; + +/** + * @internal + */ +final class SignalsHandler +{ + private $signals = array(); + + public function add($signal, $listener) + { + if (!isset($this->signals[$signal])) { + $this->signals[$signal] = array(); + } + + if (\in_array($listener, $this->signals[$signal])) { + return; + } + + $this->signals[$signal][] = $listener; + } + + public function remove($signal, $listener) + { + if (!isset($this->signals[$signal])) { + return; + } + + $index = \array_search($listener, $this->signals[$signal], true); + unset($this->signals[$signal][$index]); + + if (isset($this->signals[$signal]) && \count($this->signals[$signal]) === 0) { + unset($this->signals[$signal]); + } + } + + public function call($signal) + { + if (!isset($this->signals[$signal])) { + return; + } + + foreach ($this->signals[$signal] as $listener) { + \call_user_func($listener, $signal); + } + } + + public function count($signal) + { + if (!isset($this->signals[$signal])) { + return 0; + } + + return \count($this->signals[$signal]); + } + + public function isEmpty() + { + return !$this->signals; + } +} |