Get arguments form route attributes

@param Route $route
@return array
421110
private function extractAttributes(Route $route)
    {
        $arguments = [
            'namespace' => null,
            'controller' => null,
            'action' => null,
            'args' => []
        ];
        foreach (array_keys($arguments) as $name) {
            $arguments[$name] = array_key_exists($name, $route->attributes)
                ? $route->attributes[$name]
                : $arguments[$name];
        }
        return $arguments;
    }
483824
public function gatherRouteMiddleware(Route $route)
    {
        $middleware = collect($route->gatherMiddleware())->map(function ($name) {
            return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
        })->flatten();

        return $this->sortMiddleware($middleware);
    }
516169
protected function getRouteResource($route)
	{
		if (!config('openapischemas.resource_tag')) {
			$this->parentCommand->error('The "resource_tag" value in your apischemas.php configuration file must defined.');
			exit();
		}
		$routeAction = $route->getAction();
		list($class, $method) = explode('@', $routeAction['uses']);
		$reflection = new ReflectionClass($class);

		$comment = $reflection->getDocComment();
		if ($comment) {
			$docBlock = $this->docBlockFactory->create($comment);
			foreach ($docBlock->getTags() as $tag) {
				if ($tag->getName() === config('openapischemas.resource_tag')) {
					return $tag->getDescription()->render();
				}
			}
		}

		return null;
	}
755969
private function getParametersFromRequest(Request $request)
    {
        $parameters = $request->query->all();
        if ($routeParameters = $request->attributes->get('_route_params')) {
            $parameters = array_merge($routeParameters, $parameters);
        }

        return $parameters;
    }
161976
protected function getRouteInformation(Route $route)
	{
		$uri = head($route->methods()).' '.$route->uri();

		return $this->filterRoute(array(
			'host'   => $route->domain(),
			'uri'    => $uri,
			'name'   => $route->getName(),
			'action' => $route->getActionName(),
			'before' => $this->getBeforeFilters($route),
			'after'  => $this->getAfterFilters($route)
		));
	}
1148296
public function parseRoute (Route $route) {

		if (preg_match_all('#^' . $route->getRoute () . '$#', $this->getUrl (), $matches, PREG_OFFSET_CAPTURE)) {

			// Rework matches to only contain the matches, not the orig string
			$matches = array_slice($matches, 1);

			// Extract the matched URL parameters (and only the parameters)
			$params = array_map(function($match, $index) use ($matches) {

				// We have a following parameter: take the substring from the current param position until the next one's position (thank you PREG_OFFSET_CAPTURE)
				if (isset($matches[$index+1]) && isset($matches[$index+1][0]) && is_array($matches[$index+1][0])) {
					return trim(substr($match[0][0], 0, $matches[$index+1][0][1] - $match[0][1]), '/');
				}

				// We have no following paramete: return the whole lot
				else {
					return (isset($match[0][0]) ? trim($match[0][0], '/') : null);
				}

			}, $matches, array_keys($matches));

			if (empty ($params)) {
				return true;
			}
			else {
				return $params;
			}
		}

		return false;
	}
1262431
private function match(string $url, Route $route) : array
    {
        $regexp = $this->routeRegexp($route);

        if (preg_match_all('`^' . $regexp . '$`', $url, $matches, PREG_SET_ORDER)) {
            // remove all numeric matches
            $matches = array_diff_key($matches[0], range(0, count($matches[0])));

            // control query string
            if ($route->getUserInputs()) {
                foreach ($route->getUserInputs() as $querystring) {
                    $method = self::request()->getMethod() == 'POST' ? 'getPostOrQuery' : 'getQuery';
                    $value = self::request()->$method($querystring->getName(), $querystring->getType());

                    if (is_null($value) && $querystring->isMandatory()) {
                        return [false, null, $regexp];
                    }

                    if (!is_null($value)) {
                        $matches[$querystring->getName()] = $value;
                    }
                }
            }

            // control conditions
            if ($route->getConditions()) {
                foreach ($route->getConditions() as $condition) {
                    if (!$condition($matches)) {
                        return [false, null, $regexp];
                    }
                }
            }

            return [true, $matches, $regexp];
        }

        return [false, null, $regexp];
    }
935899
protected function getMiddleware($route)
    {
        return collect($route->gatherMiddleware())->map(function ($middleware) {
            return $middleware instanceof \Closure ? 'Closure' : $middleware;
        })->implode(',');
    }
817239
protected static function funcGet($route)
    {
        $params = self::dynamic($route);
        //
        if (count($params) > 0) {
            return 'get(\''.$route.'\',function('.self::formatParams($params).')';
        } else {
            return 'get(\''.$route.'\',function()';
        }
    }
1130551
public static function parseRoute($route)
    {
        if (!empty($route)) {
            $url = [];
            $r = explode('&', $route);
            $url[0] = $r[0];
            unset($r[0]);
            foreach ($r as $part) {
                $part = explode('=', $part);
                $url[$part[0]] = isset($part[1]) ? $part[1] : '';
            }

            return $url;
        }

        return '#';
    }
203367
static public function getRoutePatternParts( Route $route ){
		$parts	= array();
		foreach( explode( "/", $route->getPattern() ) as $part ){
			$optional	= FALSE;
			$argument	= FALSE;
			if( preg_match( "@\(:.+\)@", $part ) ){													//  optional argument found
				$part		= substr( $part, 1, -1 );												//  cut argument key
				$optional	= TRUE;																	//  note that is optional
			}
			if( substr( $part, 0, 1 ) === ":" ){													//  argument found
				$part		= substr( $part, 1 );													//  cut argument key
				$argument	= TRUE;																	//  note that is argument
			}
			$parts[]	= (object) array(															//  prepare route pattern part object
				'key'		=> $part,
				'optional'	=> $optional,
				'argument'	=> $argument,
			);
		}
		return $parts;
	}
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.',
            ]
        ];
    }
1290267
protected function getRoutePathParameters($route)
	{
		$parameters = [];

		$routeAction = $route->getAction();
		list($class, $method) = explode('@', $routeAction['uses']);

		$reflection = new ReflectionClass($class);
		$reflectionMethod = $reflection->getMethod($method);

		foreach ($reflectionMethod->getParameters() as $parameter) {
			$reflectionType = $parameter->getType();
			// Only scalar types or undefined types
			if (is_null($reflectionType) || $reflectionType->isBuiltin()) {
				$parameters[$parameter->getName()] = [
					'name' => $parameter->getName(),
				];
				if (!is_null($reflectionType) && $reflectionType->isBuiltin()) {
					$parameters[$parameter->getName()]['type'] = (string)$parameter->getType();
				}
			}
		}

		if (count($parameters) > 0) {
			// Inject the related phpdoc if exists.
			$comment = $reflectionMethod->getDocComment();
			if ($comment) {
				$docBlock = $this->docBlockFactory->create($comment);
				foreach ($docBlock->getTagsByName('param') as $tag) {
					foreach ($parameters as $parameterName => $parameter) {
						if ($tag->getVariableName() == $parameterName) {
							$docDescription = $tag->getDescription()->render();
							/** @var \ReflectionType $reflectionType */
							$reflectionType = $tag->getType();
							$parameters[$parameterName]['docType'] = (string)$reflectionType;
							$parameters[$parameterName]['docDescription'] = $docDescription;
						}
					}
				}
			}
		}

		return $parameters;
	}
1344458
private function parseRoute($route)
    {
        if (is_string($route) || is_numeric($route) || $route instanceof UriInterface) {
            $route = array_merge(
                $this->defaultRedirect,
                [ 'route' => $route ]
            );
        } else {
            if (!is_array($route)) {
                throw new InvalidArgumentException(
                    'The new path must be a string (%s) or an array structure; received %s',
                    'URI, \Psr\Http\Message\UriInterface, or the name of a \Slim\Route',
                    (is_object($route) ? get_class($route) : gettype($route))
                );
            }

            if (!isset($route['status'])) {
                $route['status'] = $this->defaultRedirect['status'];
            }

            if (!isset($route['route_type'])) {
                $route['route_type'] = null;
            }

            if (!isset($route['data_key'])) {
                $route['data_key'] = null;
            }

            if (isset($route['template_route'])) {
                $route['route']         = $route['template_route'];
                $route['methods']       = [ 'GET' ];
                $route['data_key']      = 'template_data';
                $route['route_type']    = 'templates';
                $route['template_data'] = [];
                unset($route['template_route']);
            } elseif (isset($route['action_route'])) {
                $route['route']       = $route['action_route'];
                $route['methods']     = [ 'POST' ];
                $route['data_key']    = 'action_data';
                $route['route_type']  = 'actions';
                $route['action_data'] = [];
                unset($route['action_route']);
            } elseif (isset($route['script_route'])) {
                $route['route']       = $route['script_route'];
                $route['methods']     = [ 'GET' ];
                $route['data_key']    = 'script_data';
                $route['route_type']  = 'scripts';
                $route['script_data'] = [];
                unset($route['script_route']);
            } else {
                if (isset($route['route_type'])) {
                    switch ($route['route_type']) {
                        case 'templates':
                            $route['data_key'] = 'template_data';
                            $route['methods']  = [ 'GET' ];
                            break;

                        case 'actions':
                            $route['data_key'] = 'action_data';
                            $route['methods']  = [ 'POST' ];
                            break;

                        case 'scripts':
                            $route['data_key'] = 'script_data';
                            $route['methods']  = [ 'GET' ];
                            break;

                        case 'template':
                        case 'action':
                        case 'script':
                            $route['data_key']    = $route['route_type'] . '_data';
                            $route['route_type'] .= 's';
                            $route['methods'] = ($route['route_type'] === 'actions') ? [ 'POST' ] : [ 'GET' ];
                            break;

                        default:
                            $route['data_key']   = null;
                            $route['route_type'] = null;
                    }
                }

                if (!isset($route[$route['data_key']])) {
                    $route[$route['data_key']] = [];
                }
            }

            $found = false;
            if ($route['route_type'] && isset($route['route'])) {
                $container = $this->app()->getContainer();
                $routeName = $route['route'];
                $routeType = $route['route_type'];
                $appRoutes = $container['config']['routes'];

                if (isset($appRoutes[$routeType])) {
                    $appRoutes = $appRoutes[$routeType];

                    if (isset($appRoutes[$routeName])) {
                        $route = array_merge($route, $appRoutes[$routeName]);
                        $found = true;
                    } else {
                        foreach ($appRoutes as $targetRoute) {
                            if (isset($targetRoute['ident']) && $targetRoute['ident'] === $routeName) {
                                $route = array_merge($route, $targetRoute);
                                $found = true;
                            }
                        }
                    }
                }
            }

            if ($found === false) {
                if (!isset($route['route'])) {
                    $route['route'] = $this->defaultRedirect['route'];
                }

                if (!isset($route['methods'])) {
                    $route['methods'] = $this->defaultRedirect['methods'];
                }
            }
        }

        return $route;
    }
99888
public function inflect(Route $route)
    {
        $file  = $route->attributes['controller'].'/';
        $file .= $route->attributes['action'];
        $filtered = self::camelCaseToSeparator($file, '_');
        $filtered = str_replace('_', '-', strtolower($filtered));
        return "{$filtered}.{$this->extension}";
    }
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;
    }
480896
private function getPermissionData($route)
    {
        $description = '';
        $chunks = explode('\\', $route['controller']);
        $module = strtolower(end($chunks));
        $module = str_replace('controller', '', $module);

        $messages = [
            'index'   => 'List all :modules',
            'create'  => 'Create :modules',
            'show'    => 'Preview :module',
            'edit'    => 'Update :modules',
            'destroy' => 'Delete :modules'
        ];
        $pattern = [
            '#:module#',
            '#:modules#'
        ];
        $replacement = [
            $module,
            str_plural($module)
        ];

        if (array_key_exists($route['action'], $messages)) {
            $description = preg_replace($pattern, $replacement, $messages[$route['action']]);
        }

        return [
            'resource'    => $route['resource'],
            'controller'  => $route['controller'],
            'method'      => $route['action'],
            'description' => $description,
        ];
    }