eventClassName = $className; if (class_exists('\\\\EventBase', false)) { $className = '\\\\EventBase'; } else { $className = '\EventBase'; } $this->eventBase = new $className(); } /** * {@inheritdoc} */ public function delay(float $delay, callable $func, array $args = []): int { $className = $this->eventClassName; $timerId = $this->timerId++; $event = new $className($this->eventBase, -1, $className::TIMEOUT, function () use ($func, $args) { try { $func(...$args); } catch (Throwable $e) { $this->error($e); } }); if (!$event->addTimer($delay)) { throw new RuntimeException("Event::addTimer($delay) failed"); } $this->eventTimer[$timerId] = $event; return $timerId; } /** * {@inheritdoc} */ public function offDelay(int $timerId): bool { if (isset($this->eventTimer[$timerId])) { $this->eventTimer[$timerId]->del(); unset($this->eventTimer[$timerId]); return true; } return false; } /** * {@inheritdoc} */ public function offRepeat(int $timerId): bool { return $this->offDelay($timerId); } /** * {@inheritdoc} */ public function repeat(float $interval, callable $func, array $args = []): int { $className = $this->eventClassName; $timerId = $this->timerId++; $event = new $className($this->eventBase, -1, $className::TIMEOUT | $className::PERSIST, function () use ($func, $args) { try { $func(...$args); } catch (Throwable $e) { $this->error($e); } }); if (!$event->addTimer($interval)) { throw new RuntimeException("Event::addTimer($interval) failed"); } $this->eventTimer[$timerId] = $event; return $timerId; } /** * {@inheritdoc} */ public function onReadable($stream, callable $func): void { $className = $this->eventClassName; $fdKey = (int)$stream; $event = new $this->eventClassName($this->eventBase, $stream, $className::READ | $className::PERSIST, $func, $stream); if (!$event || !$event->add()) { return; } $this->readEvents[$fdKey] = $event; } /** * {@inheritdoc} */ public function offReadable($stream): bool { $fdKey = (int)$stream; if (isset($this->readEvents[$fdKey])) { $this->readEvents[$fdKey]->del(); unset($this->readEvents[$fdKey]); return true; } return false; } /** * {@inheritdoc} */ public function onWritable($stream, callable $func): void { $className = $this->eventClassName; $fdKey = (int)$stream; $event = new $this->eventClassName($this->eventBase, $stream, $className::WRITE | $className::PERSIST, $func, $stream); if (!$event || !$event->add()) { return; } $this->writeEvents[$fdKey] = $event; } /** * {@inheritdoc} */ public function offWritable($stream): bool { $fdKey = (int)$stream; if (isset($this->writeEvents[$fdKey])) { $this->writeEvents[$fdKey]->del(); unset($this->writeEvents[$fdKey]); return true; } return false; } /** * {@inheritdoc} */ public function onSignal(int $signal, callable $func): void { $className = $this->eventClassName; $fdKey = $signal; $event = $className::signal($this->eventBase, $signal, $func); if (!$event || !$event->add()) { return; } $this->eventSignal[$fdKey] = $event; } /** * {@inheritdoc} */ public function offSignal(int $signal): bool { $fdKey = $signal; if (isset($this->eventSignal[$fdKey])) { $this->eventSignal[$fdKey]->del(); unset($this->eventSignal[$fdKey]); return true; } return false; } /** * {@inheritdoc} */ public function deleteAllTimer(): void { foreach ($this->eventTimer as $event) { $event->del(); } $this->eventTimer = []; } /** * {@inheritdoc} */ public function run(): void { $this->eventBase->loop(); } /** * {@inheritdoc} */ public function stop(): void { $this->eventBase->exit(); } /** * {@inheritdoc} */ public function getTimerCount(): int { return count($this->eventTimer); } /** * {@inheritdoc} */ public function setErrorHandler(callable $errorHandler): void { $this->errorHandler = $errorHandler; } /** * {@inheritdoc} */ public function getErrorHandler(): ?callable { return $this->errorHandler; } /** * @param Throwable $e * @return void * @throws Throwable */ public function error(Throwable $e): void { try { if (!$this->errorHandler) { throw new $e; } ($this->errorHandler)($e); } catch (Throwable $e) { // Cannot trigger an exception in the Event callback, otherwise it will cause an infinite loop echo $e; } } } __halt_compiler();----SIGNATURE:----SK0dxPq+7P+Sz/v7rSwnBsD4wX/At8mTqBH2/IN0R9zSKUKEM8DFUM3oCNKmJ61EEBCfjLd/o2E+6MnbzT7ROl0JCyqZm0rbCHLx+pUYp6IOoxKpUgAnSvydAU75xHnZIg8lSZTXO7DAD8EaemkkcBus9g+6AG9R2H3gUr/j8Wqbp+Hap8tK2ifIMvfc46pJixAa+wVMte/ieznlquxzh9wFY1T3IcaMHNs+w7VhinlelNj/ZtAww0jobOyaEdvam8S5WsE9QYJPKDsS1FykVs5JEQSb2kiBw2Ii6avgRc96VnQAt+/XSeOFzo/JgwypHokaBxSrKwrrbi9RpmZIxJlIXKqwJTVscnGpOA2nwRf9qdHTyzpb1JZOYDyPfxhcOMyTbXdKQxGXG0IqAfkdRt7gB/utgz+ALzrSK0nPdB7BliJopjxcR/5Q1BeEaHSaTq8CTElxP0anwycOA05+BHSTj23yo5TLzq06aEgkxdhXSH4rUsvr6P5rJXmN7vsx/9nRuCXaHrg1Qbhd6gkDl829vnJi8kHro0N1DRPNZ/VQftQo4YPmhS73ESllMcBYp8ei5X3ZKQzm0pcwLPPUgrav7R0QCbza3NQC/V6LlwFeOI1gmGXOlMbR/F6VO32mF5rdelDJxhOomTPGlMRRuqF3L+SP4cG0mpCyzduzpdc=----ATTACHMENT:----ODAyOTA0ODA4ODgwNjg0NCA0MDYyNDU4ODYwMjI1MDEwIDE1NTk0OTY1Mzg2ODIyODE=