Creates a container context for provided request and route

@param ServerRequestInterface $request
@param Route                  $route

@return ControllerContextInterface
428558
public function create(ServerRequestInterface $request, Route $route)
    {
        $this->uriGenerator->setRequest($request);
        return new Context($request, $route, $this->uriGenerator);
    }
1292771
public static function parse(RouteInterface $route)
    {
        extract(self::transpilePattern($route->getPattern(), false, $route->getConstraints(), $route->getDefaults()));
        $host = self::parseHostVars($route);

        return new RouteContext($staticPath, $expression, $tokens, $host['expression'], $host['tokens']);
    }
1054500
public function addRoute(RouteInterface $route)
    {
        foreach ($this->middlewares as $m) {
            $route->addMiddleware($m);
        }
        $this->routes[] = $route;
        return $this;
    }
719944
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (empty($this->requestHandler)) {
            $this->requestHandler = $this->requestHandler();
        }

        return $this->pipeline->process(
            $request->withAttribute(self::ROUTE_ATTRIBUTE, $this),
            $this->requestHandler
        );
    }
534991
public function getContext(ControllerContextInterface $context = null)
    {
        $context = new ControllerContext($context);
        $context->setRequest($this->getRequest());
        $context->setResponse($this->getResponse());
        $context->setUser($this->getUser());

        return $context;
    }
516618
public static function create(ContainerInterface $container, Request $request = null)
    {
        if (!isset($request)) {
            $request = $container['request'];
        }

        $view = new Smarty(__DIR__.'/../templates/');
        if (in_array('https', $request->getHeader('X-Forwarded-Proto'))) {
            $request = $request->withUri($request->getUri()->withScheme('https')->withPort(443));
        }

        $smartyPlugins = new SmartyPlugins($container['router'], $request->getUri()->withUserInfo(null));
        $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
        $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);

        return $view;
    }
823394
protected function runRouteWithinStack(Route $route, Request $request)
    {
        $skipMiddleware = $this->container->bound('middleware.disable') &&
                          ($this->container->make('middleware.disable') === true);

        // Create a Pipeline instance.
        $pipeline = new Pipeline(
            $this->container, $skipMiddleware ? array() : $this->gatherRouteMiddleware($route)
        );

        return $pipeline->handle($request, function ($request) use ($route)
        {
            $response = $route->run($request);

            return $this->prepareResponse($request, $response);
        });
    }
264
public function dispatch(Route $route, Request $request = null)
    {
        $context = $this->context;

        if (empty($this->context) && !empty($request)) {
            // If we have no context, but do have a request, prepare a context to store path variables in.
            // Otherwise routing path variables would be lost for no good reason.
            $context = new Context();
            $context->registerInstance($request);
        }

        if (!empty($context)) {
            // If we have a context, ensure that the route is made available in it.
            $context->registerInstance($route);

            if (!empty($request)) {
                // If we have a request, map the path variables and pass them to the context as primitive types by name.
                // This will allow us to inject info from a route e.g. "/view/$userId" to a $userId variable.
                $pathVariables = VariableUrl::extractUrlVariables($request->getRequestUri(), $route->getPattern());

                foreach ($pathVariables as $name => $value) {
                    $context->registerVariable($name, $value);
                }
            }
        }

        return $route->action($context);
    }
1160379
public function getControllerFromRoute(Route $route)
    {
        $ret = false;
        $actionParts = explode(':', $route->getDefault('_controller'));

        if (count($actionParts) == 2) {
            $ret = $this->container->get($actionParts[0]);
        }

        return $ret;
    }
666308
protected function buildCallbackFromControllerRoute($route)
    {
        list($controller, $methodName) = $this->determineClassAndMethod($route);
        $app      = & $this;
        $callable = function () use ($app, $controller, $methodName) {
            // Get action arguments
            $args = func_get_args();
            // Try to fetch the instance from Slim's container, otherwise lazy-instantiate it
            $instance = $app->container->has($controller) ? $app->container->get($controller) : new $controller($app);

            return call_user_func_array(array($instance, $methodName), $args);
        };

        return $callable;
    }
674159
protected function dispatchController($request, $route)
    {
        list($route, $var) = $this->parseUrlPath($route);

        $result = new ControllerDispatch($request, $this, implode('/', $route), $var);

        $request->setAction(array_pop($route));
        $request->setController($route ? array_pop($route) : $this->getConfig('default_controller'));
        $request->setModule($route ? array_pop($route) : $this->getConfig('default_module'));

        return $result;
    }
983434
private function injectRoutes(ServerRequestInterface $request): void
    {
        foreach ($this->routes as $key => $route) {
            // check for scheme condition
            if (! is_null($route->getScheme()) && $route->getScheme() !== $request->getUri()->getScheme()) {
                continue;
            }
            // check for domain condition
            if (! is_null($route->getHost()) && $route->getHost() !== $request->getUri()->getHost()) {
                continue;
            }
            // check for port condition
            if (! is_null($route->getPort()) && $route->getPort() !== $request->getUri()->getPort()) {
                continue;
            }

            // add a route strategy if no one is defined. Use the default router strategy.
            if (is_null($route->getStrategy())) {
                // Throw an exception if there is not a default strategy defined.
                if (is_null($this->getStrategy())) {
                    throw new RuntimeException('A defaut strategy should be defined in the Router, as there is no specific strategy defined for the Route.');
                }
                $route->setStrategy($this->getStrategy());
            }

            $routePath = $this->replaceAssertPatterns($route->getRequirements(), $route->getPath());
            $routePath = $this->replaceWordPatterns($routePath);

            $this->addRoute($route->getAllowedMethods(), $this->basePath . $routePath, $route->getIdentifier());
        }
    }
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);
        }
    }
823978
protected function buildRoute(Route $route)
    {
        if ($route->getBlock()) {
            return $route;
        }

        list($pattern, $params) = $this->parsePlaceholders($route->getPattern());
        return $route->setPatternWithoutReset($pattern)->setParams($params)->setBlock(true);
    }
587968
protected function handle(Request $request)
    {
        try {
            list($routeInformation, $parameters) = $this->findRoute($request);

            return (new Pipeline($this->container))
                ->through($routeInformation['middlewares'])
                ->send($request)
                ->then(function (Request $request) use ($routeInformation, $parameters) {
                    if ($routeInformation['action'] instanceof Closure) {
                        return call_user_func_array($routeInformation['action'], $parameters);
                    }

                    list($controller, $action) = $routeInformation['action'];
                    $controllerInstance = new $controller;

                    if ($controllerInstance instanceof KeeperBaseController) {
                        $controllerInstance->setContainer($this->container);
                        $controllerInstance->setRequest($request);
                    }

                    return call_user_func_array([$controllerInstance, $action], $parameters);
                });

        } catch (Throwable $exception) {
            if ($this->exceptionHandler) {
                return $this->exceptionHandler->handle($exception, $request);
            }

            return new Response((string)$exception, 500);
        }
    }
1342711
public function add(Route $route): self
    {
        if ($route->uri === ""
            || $route->method === 0b0
            || $route->action === null) {
            $this->logger->error("Route incomplete. Unable to add");
            $this->logger->debug("Incomplete Route", [$route]);
            throw new Exception\RouteIncompleteException(
                "Retrieved Route is not complete and can not be stored"
            );
        }

        // store default route
        if ($route->isDefault) {
            if ($this->defaultRoute === null) {
                $this->defaultRoute = $route;
            } else {
                $this->logger->debug(
                    "Default route already added to container, skipping add.",
                    ["route" => $route, "storedDefault" => $this->defaultRoute]
                );
            }
        }

        // store 404 route
        if ($route->is404) {
            if ($this->e404Route === null) {
                $this->e404Route = $route;
                $this->logger->info("404 route added to Route Container");
            } else {
                $this->logger->debug(
                    "404 route already added to container, skipping add.",
                    ["route" => $route, "stored404" => $this->e404Route]
                );
            }

            return $this;
        }

        // store route to regular container
        $this->routes[] = $route;

        $this->logger->info(
            "Route successfully added to Container",
            ["uri" => $route->uri]
        );

        return $this;
    }
14181
public static function explorer($route, $controller, $closure = null, $request) {
        $data = $dataAux = $request->bodyRequest(true);
        $controller = explode('@', $controller);
        $methodController = $controller[1];
        $controller = $controller[0];

        if(file_exists(Dir::controller($controller))) {

            if($closure)
                $data = call_user_func_array(
                    $closure,
                    array('request' => $data)
                );

            if($data === $dataAux) {
                $routeController = Dir::apiControllers($controller);
                $ctr = new $routeController();

                if(!method_exists($ctr, $methodController)) killer('404');

                $data = $ctr->$methodController($data);
                KernelHttp::makeResponse('200', $data);
            }

        } else
            killer('401');
    }