src/Provider/FileProvider.php
/**
     * Parses a route path into a route definition array.
     * @param string $path The route path to parse
     * @return array The route definition array
     */
Parses a route path into a route definition array.
@param string $path The route path to parse
@return array The route definition array
Parses a route path into a route definition array . @param string $path The route path to parse @return array The route definition array
private function parsePath($path)
    {
        $segments = array_filter(explode('/', $path), 'strlen');
        $route = [
            'path' => '/',
            'slash' => substr($path, -1) === '/',
            'params' => [],
        ];
        while ($segments && current($segments)[0] !== '{') {
            $route['path'] .= rawurlencode(array_shift($segments)) . '/';
        }
        foreach ($segments as $segment) {
            if ($segment[0] !== '{') {
                $route['params'][] = sprintf('/^%s$/', preg_quote($segment));
                continue;
            }
            if (!preg_match('/^\\{([\\w]+})(:([^}\\\\]++|\\\\\\\\|\\\\})+)?}$/', $segment, $match)) {
                throw new \InvalidArgumentException("Invalid route path '$path'");
            }
            if (isset($route['params'][$match[1]])) {
                throw new \InvalidArgumentException("Duplicate path parameter in '$path'");
            }
            $regexp = strlen($match[2]) ? sprintf('/%s/', $match[2]) : '/.*/';
            $route['params'][$match[1]] = $regexp;
        }
        return $route;
    }
private function parsePath ( $ path ) { $ segments = array_filter ( explode ( '/' , $ path ) , 'strlen' ) ; $ route = [ 'path' => '/' , 'slash' => substr ( $ path , - 1 ) === '/' , 'params' => [ ] , ] ; while ( $ segments && current ( $ segments ) [ 0 ] !== '{' ) { $ route [ 'path' ] .= rawurlencode ( array_shift ( $ segments ) ) . '/' ; } foreach ( $ segments as $ segment ) { if ( $ segment [ 0 ] !== '{' ) { $ route [ 'params' ] [ ] = sprintf ( '/^%s$/' , preg_quote ( $ segment ) ) ; continue ; } if ( ! preg_match ( '/^\\{([\\w]+})(:([^}\\\\]++|\\\\\\\\|\\\\})+)?}$/' , $ segment , $ match ) ) { throw new \ InvalidArgumentException ( " Invalid route path ' $ path ' " ) ; } if ( isset ( $ route [ 'params' ] [ $ match [ 1 ] ] ) ) { throw new \ InvalidArgumentException ( " Duplicate path parameter in ' $ path ' " ) ; } $ regexp = strlen ( $ match [ 2 ] ) ? sprintf ( '/%s/' , $ match [ 2 ] ) : '/.*/' ; $ route [ 'params' ] [ $ match [ 1 ] ] = $ regexp ; } return $ route ; }
Parses a route path into a route definition array.
Parses a route path into a route definition array .