{@inheritDoc}
@see \Duktig\Core\Route\RouteInterface::setHandler()
332188
public function setHandler($handler, $handlerMethod = null) : void
    {
        if (!is_callable($handler) && is_null($handlerMethod)) {
            throw new \InvalidArgumentException(
                'In case the $handler is not a callable, $handlerMethod must specify a method to be called'
            );
        }
        $this->handler = $handler;
        $this->handlerMethod = $handlerMethod;
    }
450822
public function andHeader($header, $value)
    {
        $this->headers->setHeader(
            new Header(new HeaderName($header), new HeaderValue($value))
        );

        return $this;
    }
762616
public function dispatch($router)
    {
        $context = $this->_context;

        if ($router instanceof RouterContext) {
            $area = $router->area;
            $controller = $router->controller;
            $action = $router->action;
            $params = $router->params;
        } else {
            $area = $router->getArea();
            $controller = $router->getController();
            $action = $router->getAction();
            $params = $router->getParams();
        }

        if ($area) {
            $area = strpos($area, '_') === false ? ucfirst($area) : Text::camelize($area);
            $context->area = $area;
        }

        $controller = strpos($controller, '_') === false ? ucfirst($controller) : Text::camelize($controller);
        $context->controller = $controller;

        $action = strpos($action, '_') === false ? $action : lcfirst(Text::camelize($action));
        $context->action = $action;

        $context->params = $params;

        if ($area) {
            if ($action === 'index') {
                if ($controller === 'Index') {
                    $context->path = $area === 'Index' ? '/' : '/' . Text::underscore($area);
                } else {
                    $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller);
                }
            } else {
                $context->path = '/' . Text::underscore($area) . '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        } else {
            if ($action === 'index') {
                $context->path = $controller === 'Index' ? '/' : '/' . Text::underscore($controller);
            } else {
                $context->path = '/' . Text::underscore($controller) . '/' . Text::underscore($action);
            }
        }

        $controllerClassName = $this->_getControllerClassName();

        /**
         * @var \ManaPHP\Rest\Controller $controllerInstance
         */
        $controllerInstance = $this->_di->getShared($controllerClassName);
        $context->controllerInstance = $controllerInstance;

        return $this->invokeAction($controllerInstance, $action, $params);
    }
471382
public function execute(string $uri = null) : ApplicationInterface
    {
        /** @var RouteInterface $route */
        $route = App::resolve('Router')->getRoute($uri);

        /** @var Middleware $middleware */
        $middleware = App::resolve('Middleware', [$route->getMiddlewares()]);

        $this->results = $middleware->dispatch(function () use ($route, $uri) {
            return App::resolve('FrontController')->dispatch($route)->getResult();
        });

        return $this;
    }
1136943
public void setHandler(IScopeHandler handler) {
        log.debug("setHandler: {} on {}", handler, name);
        this.handler = handler;
        if (handler instanceof IScopeAware) {
            ((IScopeAware) handler).setScope(this);
        }
    }
788741
public function getResolverHandler(): ResolverHandler
    {
        if (is_null(self::$globalResolverHandler)) {
            //this should be the only place where
            //a hard coded dependancy exists
            self::$globalResolverHandler = new ResolverHandler();
        }

        if (is_null($this->resolverHandler)) {
            $this->resolverHandler = self::$globalResolverHandler;
        }

        return $this->resolverHandler;
    }
666029
public void setHandler(Object handler){
        if(handler instanceof ContentHandler)
            setContentHandler((ContentHandler)handler);
        if(handler instanceof EntityResolver)
            setEntityResolver((EntityResolver)handler);
        if(handler instanceof ErrorHandler)
            setErrorHandler((ErrorHandler)handler);
        if(handler instanceof DTDHandler)
            setDTDHandler((DTDHandler)handler);
        if(handler instanceof LexicalHandler)
            setLexicalHandler((LexicalHandler)handler);
        if(handler instanceof DeclHandler)
            setDeclHandler((DeclHandler)handler);
    }
350349
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        /* @var ValidatorInterface $validator */
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);
        $serviceData    = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA);
        $validator      = App::getBean(ServiceValidator::class);

        list($className, $validatorKey) = $serviceHandler;
        $collector = ValidatorCollector::getCollector();
        if (isset($collector[$className][$validatorKey]['validator'])) {
            $validators = $collector[$className][$validatorKey]['validator'];
            $validator->validate($validators, $serviceHandler, $serviceData);
        }

        return $handler->handle($request);
    }
724841
public function setHelpers($helpers)
    {
        if ($helpers instanceof HelpersInterface) {
            $helpers = $helpers->toArray();
        }

        if (!is_array($helpers) && !$helpers instanceof Traversable) {
            throw new InvalidArgumentException(sprintf(
                'setHelpers expects an array of helpers, received %s',
                (is_object($helpers) ? get_class($helpers) : gettype($helpers))
            ));
        }

        $this->helpers = [];
        foreach ($helpers as $name => $helper) {
            $this->addHelper($name, $helper);
        }

        return $this;
    }
1016213
private function dispatch(LocateControllerInterface $router): void
    {
        // execute closures registered for dispatch start
        foreach ($this->dispatchStart as $fnc) {
            $fnc($router, $this->container);
        }

        // execute the access controllers
        foreach($router->getAbsolutePathsToAccessControllers() as $path) {
            $accessController = require($path);

            if (!$accessController instanceof \Closure)
                new \RuntimeException('Access controller must be of type Closure.');

            $newRouter = $accessController($router, $this->container);

            // start the dispatching process with the new router if the access 
            // controller returns an instance of a class implementing the
            // LocateControllerInterface
            if ($newRouter instanceof LocateControllerInterface) {
                $this->dispatch($newRouter);
                return;
            }
        }

        // execute closures registered for in between the dispatching process
        foreach ($this->dispatchBetween as $fnc) {
            $fnc($router, $this->container);
        }

        // execute the main controller
        $path = $router->getAbsolutePathToMainController();
        $mainController = require($path);

        if (!$mainController instanceof \Closure)
            new \RuntimeException('Main controller must be of type Closure.');

        $newRouter = $mainController($router, $this->container);

        // start the dispatching process with the new router if the main
        // controller returns an instance of a class implementing the
        // LocateControllerInterface
        if ($newRouter instanceof LocateControllerInterface) {
            $this->dispatch($newRouter);
            return;
        }

        // execute closures registered for dispatch end
        foreach ($this->dispatchEnd as $fnc) {
            $fnc($router, $this->container);
        }
    }
1254514
public function setHandler(AbstractHandler $handler)
    {
        $handler->setErrorHandler($this);
        $this->handler = $handler;

        return $this;
    }
1175910
public function _and(callable $callable = null)
    {
        $history = $this->whereNeedAddAndOrOr;
        $this->whereNeedAddAndOrOr = 1;

        if (is_callable($callable)) {
            $history === 0 && $this->whereNeedAddAndOrOr = 0;
            $this->lBrackets();
            call_user_func($callable, $this);
            $this->rBrackets();
        }

        return $this;
    }
1201491
private static function init_routing()
    {
        static::$container->add_singleton(
            Router::class,
            function () {
                return new Router();
            }
        );

        static::$container->add_singleton(
            Request::class,
            function () {
                return new Request();
            }
        );

        static::$container->add_singleton(
            Response::class,
            function () {
                return new Response();
            }
        );

        static::$container->add_singleton(
            Validator::class,
            function () {
                return new Validator();
            }
        );

        static::$container->alias(Router::class, 'router');
        static::$container->alias(Request::class, 'request');
        static::$container->alias(Response::class, 'response');
    }
657009
public function map(Router $router)
    {
        $router->group($this->routeAttributes(), function(Router $router) {
            \Antares\Logger\Http\Routes\LoggerRoute::register($router);
        });
    }
556985
function route($pattern,$handler,$ttl=0,$kbps=0) {
		$types=['sync','ajax','cli'];
		$alias=null;
		if (is_array($pattern)) {
			foreach ($pattern as $item)
				$this->route($item,$handler,$ttl,$kbps);
			return;
		}
		preg_match('/([\|\w]+)\h+(?:(?:@?(.+?)\h*:\h*)?(@(\w+)|[^\h]+))'.
			'(?:\h+\[('.implode('|',$types).')\])?/u',$pattern,$parts);
		if (isset($parts[2]) && $parts[2])
			$this->hive['ALIASES'][$alias=$parts[2]]=$parts[3];
		elseif (!empty($parts[4])) {
			if (empty($this->hive['ALIASES'][$parts[4]]))
				user_error(sprintf(self::E_Named,$parts[4]),E_USER_ERROR);
			$parts[3]=$this->hive['ALIASES'][$alias=$parts[4]];
		}
		if (empty($parts[3]))
			user_error(sprintf(self::E_Pattern,$pattern),E_USER_ERROR);
		$type=empty($parts[5])?0:constant('self::REQ_'.strtoupper($parts[5]));
		foreach ($this->split($parts[1]) as $verb) {
			if (!preg_match('/'.self::VERBS.'/',$verb))
				$this->error(501,$verb.' '.$this->hive['URI']);
			$this->hive['ROUTES'][$parts[3]][$type][strtoupper($verb)]=
				[$handler,$ttl,$kbps,$alias];
		}
	}
168796
public function guard($loginRoute = null)
    {
        $base = Base::instance();
        $currentPath = $base['PATH'];

        $this->parseFirewalls();

        if (
            $this->firewalls['pattern']
            && preg_match($this->firewalls['pattern'], $currentPath, $matches)
        ) {
            $key = static::pathName($matches['path']);
            $config = $this->firewalls['paths'][$key];

            if (!$this->isGranted($config['roles'])) {
                $base->reroute($loginRoute ?: $config['login_route']);
            }
        }

        return $this;
    }
306038
public function setHandlers(array $handlers)
    {
        foreach ($handlers as $handlerName => $handlerCallback)
        {
            $this->setHandler($handlerName, $handlerCallback);
        }

        return $this;
    }