Emits an event, catching all exceptions and emitting an error event for these exceptions.
@param string  $event
@param mixed   ...$arguments
@return void
@throws \CharlotteDunois\Events\UnhandledErrorException  Thrown when an error event goes unhandled.
512715
function emit(string $event, ...$arguments) {
        $errorEmpty = ($event === 'error');
        
        if(!empty($this->listeners[$event])) {
            $errorEmpty = false;
            
            foreach($this->listeners[$event] as $listener) {
                $listener(...$arguments);
            }
        }
        
        if(!empty($this->onceListeners[$event])) {
            $errorEmpty = false;
            
            $listeners = $this->onceListeners[$event];
            unset($this->onceListeners[$event]);
            
            foreach($listeners as $listener) {
                $listener(...$arguments);
            }
        }
        
        if($errorEmpty) {
            throw new \CharlotteDunois\Events\UnhandledErrorException('Unhandled error event', 0, (($arguments[0] ?? null) instanceof \Throwable ? $arguments[0] : null));
        }
    }
1039764
public function emit($event, array $arguments = [])
    {
        parent::emit($event, $arguments);
        if ($this->broker) {
            $this->broker->emit($event, $arguments);
        }
    }
46008
protected function emitWithoutCancellingPropagationCheck(string $eventName, array $arguments = []): void
    {
        foreach ($this->getEventSubscribers($eventName) as $subscriber) {
            call_user_func_array($subscriber, $arguments);
        }
    }
391260
public function onReflectError($event)
    {
        $filename = $event['file']->getPathname();
        $this->stopwatch->stop($filename);

        self::$logger->error(
            'Parse error in {time} on file "{file"}: {error}',
            array(
                'time'  => Timer::toTimeString($time),
                'file'  => $filename,
                'error' => $event['error']
            )
        );
    }
703071
public function addError(...$args) {
        $args = func_get_args();
        if(func_num_args()>2){
            foreach ($args as $error) {
                array_push($this->errors, $error);
            }
        } else {
            if(func_get_args()==1) {
                $this->errors[] = $args[0];
            } else {
                $this->errors[$args[0]] = $args[1];
            }
        }
    }
981739
public function enableErrorHandler(array $options = []): void
    {
        if ($this->errorHandlerEnabled) {
            throw new \Exception('The error handler is already enabled!');
        }
        set_exception_handler(function($exception) use ($options) {
            \BearFramework\Internal\ErrorHandler::handleException($this, $exception, $options);
        });
        register_shutdown_function(function() use ($options) {
            $errorData = error_get_last();
            if (is_array($errorData)) {
                \BearFramework\Internal\ErrorHandler::handleFatalError($this, $errorData, $options);
            }
        });
        set_error_handler(function($errorNumber, $errorMessage, $errorFile, $errorLine) {
            throw new \ErrorException($errorMessage, 0, $errorNumber, $errorFile, $errorLine);
        });
        $this->errorHandlerEnabled = true;
    }
234296
private function fireEvent($event, ...$params)
    {
        if (!$this->eventManager) {
            return;
        }

        $this->eventManager->handle($event, ...$params);
    }
1287997
public function onRunFailed(RunEvent $event)
    {
        $this->exceptions = array_merge($this->exceptions, $event->getRun()->getExceptions());
    }
55475
public function fireReturn(string $event, array $arguments = null) {
        return $this->getEventManager()->fireReturn($event, $arguments);
    }
435547
public function fire($event_type, ...$arguments)
    {
        $event_type = (string) $event_type;

        if (isset($this->callbacks[$event_type])) {
            foreach ($this->callbacks[$event_type] as &$callback) {
                $callback(...$arguments);
            }
        }
    }
745557
public static function onRequestError(Event $event)
    {
        $e = BadResponseException::factory($event['request'], $event['response']);
        $event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
        throw $e;
    }
419828
protected function fire(string $event, array $args = [])
    {
        if (!$cb = $this->getOption($event)) {
            return null;
        }

        return RouteHelper::call($cb, $args);
    }
358250
public static function fire($event, $data = null)
    {
        if (!is_array($data)) {
            $data = array($data);
        }
        array_unshift($data, $event);

        $retval = true;

        foreach (array('*', $event) as $e) {
            if (!array_key_exists($e, self::$events)) {
                continue;
            }

            foreach (self::$events[$e] as $callback) {
                if (!is_callable($callback)) {
                    continue;
                }

                if (($retval = call_user_func_array($callback, $data)) === false) {
                    break 2;
                }
            }
        }

        return $retval !== false;
    }
448110
public function onConsoleException(ConsoleExceptionEvent $event)
    {
        if (!$this->auto) {
            return;
        }

        $exception = $event->getException();

        $meta = [
            'command' => [
                'name' => $event->getCommand()->getName(),
                'status' => $event->getExitCode(),
            ],
        ];

        $report = Report::fromPHPThrowable(
            $this->client->getConfig(),
            $exception
        );
        $report->setUnhandled(true);
        $report->setSeverityReason([
            'type' => 'unhandledExceptionMiddleware',
            'attributes' => [
                'framework' => 'Symfony',
            ],
        ]);
        $report->setMetaData($meta);

        $this->client->notify($report);
    }
241630
protected function handleError(Event $event): void
    {
        $logErrors = $this->configuration
            ->get('log_errors')
        ;
        $emailErrors = $this->configuration
            ->get('email_errors')
        ;

        if ($logErrors) {
            $this->logger->error($this->formatEventError($event));
        } else {
            $output = $event->wholeOutput();

            $this->output
                ->write("<error>{$output}</error>");
        }

        // Send error as email as configured
        if ($emailErrors) {
            $this->mailer->send(
                'Crunz: reporting error for event:' . (($event->description) ? $event->description : $event->getId()),
                $this->formatEventError($event)
            );
        }
    }
283443
public function fire(string $event, ...$args): bool
    {
        if (!isset(self::$events[$event])) {
            return false;
        }

        // call event handlers of the event.
        foreach ((array)self::$eventHandlers[$event] as $cb) {
            // return FALSE to stop go on handle.
            if (false === $cb(...$args)) {
                break;
            }
        }

        // is a once event, remove it
        if (self::$events[$event]) {
            return $this->off($event);
        }

        return true;
    }
21371
public function on($event, $callback)
        {
            if (!is_callable($callback)) {
                throw new Exception('Socketio::on() type callback must be callable.');
            }

            if (!isset($this->callbacks[$event])) {
                $this->callbacks[$event] = array();
            }

            // @TODO Handle case where callback is a string
            if (in_array($callback, $this->callbacks[$event])) {
                $this->stdout('debug', 'Skip existing callback');
                return;
            }

            $this->callbacks[$event][] = $callback;
        }