@param string|object|callable $messageHandler

@return SingleHandlerRouter

@throws Exception\RuntimeException
@throws Exception\InvalidArgumentException
177965
public function to($messageHandler): SingleHandlerRouter
    {
        if (! \is_string($messageHandler) && ! \is_object($messageHandler) && ! \is_callable($messageHandler)) {
            throw new Exception\InvalidArgumentException(\sprintf(
                'Invalid message handler provided. Expected type is string, object or callable but type of %s given.',
                \gettype($messageHandler)
            ));
        }

        if (null === $this->tmpMessageName) {
            throw new Exception\RuntimeException(\sprintf(
                'Cannot map handler %s to a message. Please use method route before calling method to',
                \is_object($messageHandler)
                    ? \get_class($messageHandler)
                    : (\is_string($messageHandler) ? $messageHandler : \gettype($messageHandler))
            ));
        }

        $this->messageMap[$this->tmpMessageName] = $messageHandler;

        $this->tmpMessageName = null;

        return $this;
    }
219165
protected function callHandler(callable $handler, $payload)
    {
        try {
            return $handler($payload);
        } catch (\Exception $e) {
            if (property_exists($this, 'app') && $this->app instanceof ServiceContainer) {
                $this->app['logger']->error($e->getCode().': '.$e->getMessage(), [
                    'code' => $e->getCode(),
                    'message' => $e->getMessage(),
                    'file' => $e->getFile(),
                    'line' => $e->getLine(),
                ]);
            }
        }
    }
632324
public function getHandlerFor(string $type)
    {
        if (empty($this->handlers[$type])) {
            throw new \InvalidArgumentException('There is no handler for the "'.$type.'" criteria type.');
        } elseif (is_object($this->handlers[$type]) && $this->handlers[$type] instanceof CriteriaHandler) {
            return $this->handlers[$type];
        }

        return new $this->handlers[$type];
    }
139553
public function getHandler($identifier)
    {
        if (isset($this->metaTagHandlers[$identifier])) {
            return $this->metaTagHandlers[$identifier];
        }

        throw new HandlerNotFoundException($identifier);
    }
307878
public function setHandler($handlerName, $handlerCallback)
    {
        $this->checkHandlerName($handlerName);

        if (!is_callable($handlerCallback))
        {
            throw new RuntimeException("Handler callback must be callable");
        }

        $this->handlers[$handlerName] = $handlerCallback;

        return $this;
    }
977085
public function getLogger(): MonoLogger
    {
        if ($this->logger === null) {
            $this->logger = new MonoLogger($this->name);
            $this->logger->pushHandler(new StreamHandler($this->logfile));
        }

        return $this->logger;
    }
1092928
public function addCallableHandle()
    {
        if ($this->handler) {
            throw new AlreadyBuildedException('The handler already builded.');
        }

        $loader = new CallableLoader();
        $resolver = new CallableResolver();

        $this->addCallableResolver($resolver);
        $this->addActionLoader($loader);

        return $loader;
    }
506040
protected function createHandler(string $name): TaskHandler
    {
        $handler = Reflection::newInstance(ltrim($name, '\\'));

        if ($handler instanceof TaskHandler) {
            return $handler;
        }

        throw new RuntimeException('Task ' . $name . ' handler must implements `TaskHandler` interface');
    }
1358975
public function withHandler(RequestHandlerInterface $handler): self
    {
        $pipeline = clone $this;
        $pipeline->handler = $handler;
        $pipeline->position = 0;

        return $pipeline;
    }
810076
public function setMessageHandler($callback = null, $option = self::ALL_MSG)
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('Argument #2 is not callable.');
        }

        $this->messageHandler = $callback;
        $this->messageFilter = $option;

        return $this;
    }
280249
private function handleMessage($messageData): \Generator
    {
        $messageType = implode('|', [
            ErrorResponse::class,
            ResultResponse::class,
            Notification::class,
            Request::class,
        ]);

        try {
            /** @var Message $message */
            $message = $this->mapper->load($messageData, $messageType);

            if ($message->jsonrpc !== Message::VERSION) {
                $this->logger->warning('[jsonrpc] Bad JSONRPC version received');
            }
        } catch (MapperException $e) {
            $this->logger->warning('[jsonrpc] Malformed message received');

            return new ErrorResponse(null, new InvalidRequestException());
        }

        if ($message instanceof Response) {
            return yield $this->handleResponse($message);
        }
        if ($message instanceof Request) {
            return yield $this->handleRequest($message);
        }
        if ($message instanceof Notification) {
            return yield $this->handleNotification($message);
        }

        throw new \LogicException(); // @codeCoverageIgnore
    }
89724
private function initMessageHandler()
    {
        $this->di->mapFactory('core.message.message_handler', '\Core\Message\MessageHandler');
        $this->di->mapFactory('core.message.message_storage', '\Core\Message\MessageStorage');
        $this->di->mapFactory('core.message.message', '\Core\Notification\Notifcation');

        /* @var $handler \Core\Message\MessageHandler */
        $handler = $this->di->get('core.message.message_handler');

        // Init a message session array if not exists until now
        if (empty($_SESSION['Core']['messages'])) {
            $_SESSION['Core']['messages'] = [];
        }

        // Create the message storage
        /* @var $storage \Core\Message\MessageStorage */
        $storage = $this->di->get('core.message.message_storage');
        $storage->setStorage($_SESSION['Core']['messages']);

        $handler->setStorage($storage);

        $this->message = new MessageFacade($handler);

        // Map the handler as frameworks default messagehandler
        $this->di->mapValue('core.message.default', $handler);
    }
190926
protected function getMonologHandler()
  {
    $name = Str::slug($this->getNamespaceName());
    return (new StreamHandler($this->storagePath("logs/{$name}.log"), Logger::DEBUG))
      ->setFormatter(new LineFormatter(null, null, true, true));
  }
699697
protected function getHandler(): HandlerInterface
	{
		$handler = new StreamHandler($this->app->getPath() . '/storage/logs/' . date('Y-m-d') . '.mako');

		$formatter = new LineFormatter(null, null, true, true);

		$formatter->includeStacktraces();

		$handler->setFormatter($formatter);

		return $handler;
	}
851443
public function route(Route $route, $handler) 
  {
    if (!is_callable($handler)) {
      throw new \InvalidArgumentException('Route handler must be callable.');
    }

    $this->currentContext->addRoute($route, $handler);
    return $this;
  }
261861
public function to($handler): RegexRouter
    {
        if (! \is_string($handler) && ! \is_object($handler) && ! \is_callable($handler)) {
            throw new Exception\InvalidArgumentException(\sprintf(
                'Invalid handler provided. Expected type is string, object or callable but type of %s given.',
                \gettype($handler)
            ));
        }

        if (null === $this->tmpPattern) {
            throw new Exception\RuntimeException(\sprintf(
                'Cannot map handler %s to a pattern. Please use method route before calling method to',
                \is_object($handler)
                    ? \get_class($handler)
                    : (\is_string($handler) ? $handler : \gettype($handler))
            ));
        }

        $this->patternMap[] = [$this->tmpPattern => $handler];

        $this->tmpPattern = null;

        return $this;
    }
887202
public function handler(RouteHandlerInterface $handler)
    {
        $this->_method('before', [$handler, 'before']);
        $this->_method('wrap', [$handler, 'wrap']);
        $this->_method('after', [$handler, 'after']);

        return $this;
    }