Dispatches a handle action taking into account the routing parameters

@param \ManaPHP\RouterInterface $router

@return mixed
@throws \ManaPHP\Dispatcher\NotFoundControllerException
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);
    }
227495
protected function requestHandler(): RequestHandlerInterface
    {
        if (!$this->hasContainer()) {
            throw new RouteException("Unable to configure route pipeline without associated container.");
        }

        if ($this->target instanceof TargetInterface) {
            try {
                return $this->target->getHandler($this->container, $this->matches);
            } catch (TargetException $e) {
                throw new RouteException("Invalid target resolution", $e->getCode(), $e);
            }
        }

        if ($this->target instanceof RequestHandlerInterface) {
            return $this->target;
        }

        try {
            if (is_object($this->target) || is_array($this->target)) {
                $target = $this->target;
            } else {
                $target = $this->container->get($this->target);
            }

            if ($target instanceof RequestHandlerInterface) {
                return $target;
            }

            return new CallableHandler(
                $target,
                $this->container->get(ResponseFactoryInterface::class)
            );
        } catch (ContainerExceptionInterface $e) {
            throw new RouteException($e->getMessage(), $e->getCode(), $e);
        }
    }
41057
protected function _prepareRouter($router)
    {
        // Wrap Route That Make it usable for Route Stack Wrapper
        if (!$router instanceof iRouterStack)
            $router = new RouteStackChainWrapper($router);

        $router->setParent($this);


        $routeName = $this->getName().self::SEPARATOR.$router->getName();

        $router->setName($routeName);

        ## check if router name exists
        if (array_key_exists($routeName, $this->_routes_strict_override))
            throw new \RuntimeException(sprintf(
                'Router with name (%s) exists and not Allowed Override.'
                , $routeName
            ));

        return $router;
    }
1110588
public function addRouter(RouterInterface $router)
    {
        $this->router[] = $router;
        $router->setContext($this->context);
    }
30679
public static function apiRoutes(\Illuminate\Routing\Router $router)
    {
        $router->group(['prefix' => 'translations'], function (\Illuminate\Routing\Router $router) {

            $router->get('/index', [
                'as'   => 'translations.api.index',
                'uses' => ApiController::class . '@index'
            ]);
        });
    }
405415
public function dispatch(callable $controller, array $vars = [], BaseRoute $route = null)
    {
        if ($group = $route->getParentGroup()) {
            $this->response = (new PipelineProcessor())
                ->handlePayload(new Payload($group, $this->request, $this->response))
                ->getResponse();
        }

        $this->response = (new PipelineProcessor())
            ->handlePayload(new Payload($route, $this->request, $this->response))
            ->getResponse();

        return \call_user_func_array(
            $controller,
            [$this->request, $this->response, $vars]
        );
    }
444604
public function route(RouterInterface $router, string $path, string $filter, array &$vars) : bool
    {
        // dispatch if no paths remain in buffer(means last node)
        if (empty($path)){
            if (empty($filter)){
                $event = $this->filters['*'] ?? '';
            }
            else{
                $event = $this->filters[$filter] ?? $this->filters['*'] ?? '';
                if(!$event){
                    foreach($this->filters as $filter => $e){
                        if ($filter === self::FILTER_KEY_DEFAULT){
                            $event = $e;
                        }
                    }
                }
            }
            if (!empty($event)){
                $router->dispatch($vars, $event);
                return true;
            }
        }
        return parent::route($router, $path, $filter, $vars);
    }
40879
protected function getHandlerForRoute(Route $route, ProtocolInterface $protocol)
    {
        $handlerId = $route->getDefault(Protocol::OPTION_HANDLER);
        if ($handlerId) {
            $handlerId = substr($handlerId, 1);

            return $this->getContainer()->get($handlerId);
        } else {
            return $protocol->getDefaultHandler();
        }
    }
6966
public function dispatch($method, $uri)
    {
        $routeInfo = $this->dispatcher->dispatch($method, $uri);

        if($routeInfo[0] === Dispatcher::NOT_FOUND) {

            $this->filterRequest('*', $method);

            $routeInfo = $this->dispatcher->dispatch($method, '*');

            if(!$routeInfo[0]) {
                throw new Exception("Route [ {$uri} ] not found.");
            }
        }

        if($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
            $method = $_SERVER['REQUEST_METHOD'];
            throw new Exception("[ $method ] method not allowed.");
        }

        if($routeInfo[0] === Dispatcher::FOUND) {
            $handler = $routeInfo[1];
            $params = $routeInfo[2];

            if(!empty($filterResponse = $this->filterRequest($uri, $method))) {
                return $filterResponse;
            }

            return $this->methodDispatcher($handler, $params);
        }
    }
78063
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        /** @var Route $route */
        $route = $request->getAttribute('route', false);
        $this->setAttributes($route);
        $class = $this->namespace.'\\'.$this->controller;
        try {
            $controller = $this->createController($class);
            $controller->register($request, $response);

            $this->checkAction($class);

            call_user_func_array([$controller, $this->action], $this->args);
            $request = $controller->getRequest();
            $request = $this->setViewVars($controller, $request);
            $response = $controller->getResponse();
        } catch (ControllerNotFoundException $caught) {
            $this->checkView($request, $caught);
        }

        return $this->executeNext($request, $response);
    }
331275
public function setRouter($Router)
    {
        if (! is_object($Router) || ! $Router instanceof Router) {
            throw new \InvalidArgumentException(
                'The Router Interface must be a valid Router Object'
            );
        }
        $this->Router = $Router;

        return true;
    }
838615
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $result = $this->router->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        return $handler->handle(
            $request->withAttribute('routing', $result)
        );
    }
832698
public function addSlimPlugins(RouterInterface $router, $uri)
    {
        $smartyPlugins = new SmartyPlugins($router, $uri);
        $this->smarty->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
        $this->smarty->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
    }
730250
protected function dispatchRouter($method, $path)
    {
        $router = $this->container['router'];
        $logger = $this->container['logger'];

        $logger->debug('Router dispatch.', ['method' => $method, 'path' => $path]);

        $router->init();
        $route_info = $router->dispatch($method, $path);

        $handler = null;
        $vars = [];

        switch ($route_info[0]) {
        case RouteDispatcher::NOT_FOUND:
            $logger->debug('Routing failed. Not Found.');
            throw new HttpNotFoundException('404 Not Found');
            break;
        case RouteDispatcher::METHOD_NOT_ALLOWED:
            $logger->debug('Routing failed. Method Not Allowd.');
            throw new HttpMethodNotAllowedException('405 Method Not Allowed');
            break;
        case RouteDispatcher::FOUND:
            $handler = $route_info[1];
            $vars = $route_info[2];
            $logger->debug('Route found.', ['handler' => $handler]);
            break;
        }

        return [$handler, $vars];
    }
376416
public function setRouter(Router $router)
    {
        $this->setParam('router', $router);
        $this->router = $router;
        return $this;
    }
454544
public function setRoute(RouteInterface $route): RouterInterface
    {
        $regexp = $route->getRegexp();
        $this->_routes[$regexp] = $route;
        return $this;
    }
536927
protected function dispatchRouterRoute(
        ServerRequestInterface $request,
        RouterInterface $router
    ) : ServerRequestInterface {
        $routeInfo = $router->dispatch($request);
        if ($routeInfo[0] === Dispatcher::FOUND) {
            $routeArguments = [];
            foreach ($routeInfo[2] as $k => $v) {
                $routeArguments[$k] = urldecode($v);
            }

            $route = $router->getRouteByIdentifier($routeInfo[1]);
            $route->prepare($request, $routeArguments);
            /**
             * Add route to request to allow handler or other access route
             */
            $request = $request->withAttribute('route', $route);
        }

        $routeInfo['request'] = [$request->getMethod(), (string) $request->getUri()];
        return $request->withAttribute('routeInfo', $routeInfo);
    }