Maps all the query parameters to the controller action parameters

@param RouteEndpoint $route

@return string[]
@throws HttpException
@throws ReflectionException
15640
private function mapQueryToActionParameters(RouteEndpoint $route, RequestInterface $request) : array
    {
        $reflection = new ReflectionClass($route->getFullyQualifiedName());
        $method = $reflection->getMethod($route->getAction(true));
        $query = $request->getQuery();

        $mapper = [];
        foreach ($method->getParameters() as $parameter) {
            $defaultValue = null;
            if ($parameter->isDefaultValueAvailable()) {
                $defaultValue = $parameter->getDefaultValue();
            }

            $value = $query->get($parameter->getName(), $defaultValue);

            // We are missing a required parameter, so this is a bad request
            if ($value === null && !$parameter->allowsNull()) {
                throw HttpException::badRequest();
            }

            $mapper[$parameter->getName()] = $value;
        }

        return $mapper;
    }
580264
public function convertRouteParam($route)
    {
        $patterns = array(
            ':any?' => ':[a-zA-Z0-9\.\-_%=]?+',
            ':num?' => ':[0-9]?+',
            ':all?' => ':.?*',
            ':num' => ':[0-9]+',
            ':any' => ':[a-zA-Z0-9\.\-_%=]+',
            ':all' => ':.*',
        );

        $route = str_replace(array_keys($patterns), array_values($patterns), $route);

        return $route;
    }
979626
public function gatherRouteMiddlewares( Route $route )
	{
		return Collection::make( $route->middleware() )->map( function ( $name )
		{
			return Collection::make( $this->resolveMiddlewareClassName( $name ) );
		} )->flatten()->all();
	}
709553
protected function callPatternFilters($route, $request)
	{
		foreach ($this->findPatternFilters($request) as $filter => $parameters)
		{
			$response = $this->callRouteFilter($filter, $parameters, $route, $request);

			if ( ! is_null($response)) return $response;
		}
	}
1165717
public function callbackFunction($route = null, $parameters = [])
    {
        if ($route === null || ! is_string($route)) {
            // Gets URI from current request
            $uri = $this->request->getUri();
        } else {
            // Generates URI from '_route'
            $uri = $this->router->generate(
                $route,
                $parameters,
                Router::ABSOLUTE_URL
            );
        }

        $result = parse_url($uri);

        // When uri contains query string
        if (isset($result['query'])) {

            parse_str($result['query'], $query);

            // Remove callback from query
            $query = array_diff_key($query, ['callback' => null]);
        } else {
            // Return unchanged uri
            return $uri;
        }

        return $result['scheme'].'://'.
               (isset($result['user']) ? $result['user'] : '').
               (isset($result['pass']) ? ':'.$result['pass'].'@' : '').
               $result['host'].
               (isset($result['port']) ? ':'.$result['port'] : '').
               (isset($result['path']) ? $result['path'] : '').
               ($query != [] ? '?'.http_build_query($query) : '').
               (isset($result['fragment']) ? '#'.$result['fragment'] : '');
    }
884441
public function parse($route)
    {
        // reset param names
        $this->paramNames = [];

        // replace shortcuts
        $regex = strtr($route, $this->shortcuts);

        // replace param names that doesn't include shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+)}/', [$this, 'replaceWithoutRegex'], $regex);

        // replace param names that includes shortcuts or regex
        $regex = preg_replace_callback('/{([a-zA-Z0-9]+):/', [$this, 'replaceWithRegex'], $regex);

        // replace ending grouping
        $regex = str_replace('}', ')', $regex);

        // fix slashes when optional params are present
        $regex = $this->fixOptionalSlashes($regex);

        // fix for handling trailing slashes
        $regex .= '(/)?';

        // return regex and param names
        return ['#^'. $regex .'$#', $this->paramNames];
    }
945634
public function resolve(RouteInterface $route)
    {
        if (is_string($handler = $route->handler()))
        {
            $handler = explode('@', $handler);
        }

        $parameters = (array) $route->parameters();

        list($handler, $reflection) = $this->reflection($handler);

        $parameters = $this->arguments($reflection, $parameters);

        return call_user_func_array($handler, $parameters);
    }
638147
public static function route($route, array $params = array())
    {
        list($controller, $action) = Route::routeToAction($route);
        $controller = substr($controller, 0, strlen($controller) - strlen('Controller'));
        $action = substr($action, 0, strlen($action) - strlen('Action'));

        $path = "/" . str_ireplace('\\', '/', $controller) . '/' . $action;
        $query = http_build_query($params);

        $url = $path . (empty($query) ? '' : ('?' . $query));

        return $url;
    }
1129838
public function getMethodsByRoute($route)
    {
        // Check if a route was provided
        if (!$route) {
            return [];
        }

        // Loop through our routes
        $methods = [];
        foreach ($this->routes as $method => $routes) {
            foreach ($routes as $availableRoute => $callable) {
                // Check if the available route is the same as the specified route
                if ($availableRoute === $route) {
                    $methods[] = $method;
                    continue 2;
                }

                // Check if the route matches
                $regex = '/^' . str_replace('/', '\/', $availableRoute) . '/Uim';
                if (preg_match($regex, $route, $matches) === 1 && $matches[0] === $route) {
                    $methods[] = $method;
                    continue 2;
                }
            }
        }

        // Return the methods array
        return $methods;
    }
239588
protected function getProtocolForRoute(Route $route)
    {
        $protocolId = $route->getDefault(Protocol::OPTION_PROTOCOL);
        if (!$protocolId) {
            throw new InvalidConfigurationException(sprintf(
                'Route "%s" has no protocol defined',
                $route->getPath()
            ));
        }

        $protocolId = substr($protocolId, 1);

        return [$protocolId, $this->getContainer()->get($protocolId)];
    }
1265968
protected function getSchemaRoutes(Route $route)
    {
        $path = $route->getPath();

        $describedService = substr(substr($path, 7), 0, substr($path, -5) == '/item' ? -7 : -10);

        $tags = array_merge(['Schema'], $this->getPathTags($route, 2));

        return [
            $path,
            'get',
            [
                'produces' => [
                    'application/json',
                ],
                'responses' => [
                    200 => [
                        'description' => 'JSON-Schema for ' . $describedService . '.',
                        'schema' => ['$ref' => '#/definitions/SchemaModel'],
                    ]
                ],
                'tags' => $tags,
                'summary' => 'Get schema information for ' . $describedService . ' endpoints.',
            ]
        ];
    }
1054063
protected function addFilters(Controller $controller, $action, Request $request, Route $route=null) {
		$controllerClass = get_class($controller);

		foreach($this->filters as $_filter) {
			$args = $_filter['args'];
			$filter = $_filter['filter'];

			if(isset($criteria)) {
				$criteria = $_filter['criteria'];
				if(isset($criteria['actions'])) {
					if(!is_string($action))
						continue;
					if($criteria['actions'] && strpos($controllerClass.':'.$action, $criteria['actions']) !== 0)
						continue;
				}
				if($route !== null && isset($criteria['route'])) {
					foreach($criteria['methods'] as $method) {
						if($criteria['route'] && strpos($route->getRoute(), $criteria['route']) !== 0 || strtoupper($method) !== $request->method())
							continue;
					}
				}
			}

			$reflector = new \ReflectionClass($filter);
			$controller->addFilter($reflector->newInstanceArgs($args));
		}

		foreach($this->beforeFilters as $_filter) {
			$filter = $_filter['filter'];

			if(isset($criteria)) {
				$criteria = $_filter['criteria'];
				if(isset($criteria['actions'])) {
					if(!is_string($action))
						continue;
					if($criteria['actions'] && strpos($controllerClass.':'.$action, $criteria['actions']) !== 0)
						continue;
				}
				if($route !== null && isset($criteria['route'])) {
					foreach($criteria['methods'] as $method) {
						if($criteria['route'] && strpos($route->getRoute(), $criteria['route']) !== 0 || strtoupper($method) !== $request->method())
							continue;
					}
				}
			}

			$controller->addBeforeFilter($filter);
		}

		foreach($this->afterFilters as $_filter) {
			$filter = $_filter['filter'];

			if(isset($criteria)) {
				$criteria = $_filter['criteria'];
				if(isset($criteria['actions'])) {
					if($criteria['actions'] && strpos($controllerClass.':'.$action, $criteria['actions']) !== 0)
						continue;
				}
				if($route !== null && isset($criteria['route'])) {
					foreach($criteria['methods'] as $method) {
						if($criteria['route'] && strpos($route->getRoute(), $criteria['route']) !== 0 || strtoupper($method) !== $request->method())
							continue;
					}
				}
			}

			$controller->addAfterFilter($filter);
		}
	}
1021582
public static function endpointsInfo(Application $app)
    {
        $app->boot();

        /** @var ControllerCollection $controllers */
        $controllers = $app['controllers'];
        $rControllers = new ReflectionObject($controllers);
        $pControllers = $rControllers->getProperty('controllers');
        $pControllers->setAccessible(true);

        /** @var Controller $ctrl */
        foreach ($pControllers->getValue($controllers) as $ctrl) {
            if ($ctrl instanceof Controller) {
                $route = $ctrl->getRoute();

                foreach ($route->getMethods() as $method) {
                    echo '- ' . str_pad($method, 7) . ' ' . str_pad($route->getPath(), 70);

                    if ($service = $route->getDefault('_controller')) {
                        if (is_scalar($service)) {
                            echo 'Handler: ' . $service;
                        }
                    }

                    echo "\n";
                }
            }
        }
    }
984262
private function resolveActionParams(): array
    {
        $actionParams = [];

        for ($i = 2; $i < count($this->routeParams); $i++) {
            $actionParams[] = $this->routeParams[$i];
        }

        return $actionParams;
    }
79787
protected function getRouteApiParts($route)
    {
        $name = explode('/', $route->getPattern());

        $parts = array(
            'exposed' => false
        );

        // if the name has more than one string pattern
        if (count($name) > 2){
            // get the method name
            $method = array_pop($name);

            // upcase the namespace names
            array_walk($name, function(&$n){
                $n = ucfirst($n);
            });

            $path = implode('', $name);

            $parts = array(
                'path' => $path,
                'exposed' => true,
                'name' => $method,
                'len' => 1
            );

            if ($route->isFormDirect()){
                $parts['formHandler'] = true;
            }

        }

        return $parts;
    }
789252
public function gatherRouteMiddlewares(LaravelRoute $route)
    {
        $middlewares = [];

        foreach ($route->middleware() as $name) {
            $middlewares[] = $this->resolveMiddlewareClassName($name);
        }
        return Arr::flatten($middlewares);
    }
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);
    }