protected function compileRoute($route)
    {
        // First escape all of the non-named param (non [block]s) for regex-chars
        $route = preg_replace_callback(
            static::ROUTE_ESCAPE_REGEX,
            function ($match) {
                return preg_quote($match[0]);
            },
            $route
        );

        // Get a local reference of the match types to pass into our closure
        $match_types = $this->match_types;

        // Now let's actually compile the path
        $route = preg_replace_callback(
            static::ROUTE_COMPILE_REGEX,
            function ($match) use ($match_types) {
                list(, $pre, $type, $param, $optional) = $match;

                if (isset($match_types[$type])) {
                    $type = $match_types[$type];
                }

                // Older versions of PCRE require the 'P' in (?P<named>)
                $pattern = '(?:'
                         . ($pre !== '' ? $pre : null)
                         . '('
                         . ($param !== '' ? "?P<$param>" : null)
                         . $type
                         . '))'
                         . ($optional !== '' ? '?' : null);

                return $pattern;
            },
            $route
        );

        $regex = "`^$route$`";

        // Check if our regular expression is valid
        $this->validateRegularExpression($regex);

        return $regex;
    }
protected function compileRoute($route)
    {
        // First escape all of the non-named param (non [block]s) for regex-chars
        $route = preg_replace_callback(
            static::ROUTE_ESCAPE_REGEX,
            function ($match) {
                return preg_quote($match[0]);
            },
            $route
        );

        // Get a local reference of the match types to pass into our closure
        $match_types = $this->match_types;

        // Now let's actually compile the path
        $route = preg_replace_callback(
            static::ROUTE_COMPILE_REGEX,
            function ($match) use ($match_types) {
                list(, $pre, $type, $param, $optional) = $match;

                if (isset($match_types[$type])) {
                    $type = $match_types[$type];
                }

                // Older versions of PCRE require the 'P' in (?P<named>)
                $pattern = '(?:'
                         . ($pre !== '' ? $pre : null)
                         . '('
                         . ($param !== '' ? "?P<$param>" : null)
                         . $type
                         . '))'
                         . ($optional !== '' ? '?' : null);

                return $pattern;
            },
            $route
        );

        $regex = "`^$route$`";

        // Check if our regular expression is valid
        $this->validateRegularExpression($regex);

        return $regex;
    }
protected function compileRoute ( $ route ) { // First escape all of the non-named param (non [block]s) for regex-chars $ route = preg_replace_callback ( static :: ROUTE_ESCAPE_REGEX , function ( $ match ) { return preg_quote ( $ match [ 0 ] ) ; } , $ route ) ; // Get a local reference of the match types to pass into our closure $ match_types = $ this -> match_types ; // Now let's actually compile the path $ route = preg_replace_callback ( static :: ROUTE_COMPILE_REGEX , function ( $ match ) use ( $ match_types ) { list ( , $ pre , $ type , $ param , $ optional ) = $ match ; if ( isset ( $ match_types [ $ type ] ) ) { $ type = $ match_types [ $ type ] ; } // Older versions of PCRE require the 'P' in (?P<named>) $ pattern = '(?:' . ( $ pre !== '' ? $ pre : null ) . '(' . ( $ param !== '' ? "?P<$param>" : null ) . $ type . '))' . ( $ optional !== '' ? '?' : null ) ; return $ pattern ; } , $ route ) ; $ regex = "`^$route$`" ; // Check if our regular expression is valid $ this -> validateRegularExpression ( $ regex ) ; return $ regex ; }
Compiles a route string to a regular expression

@param string $route     The route string to compile
@return string
Compiles a route string to a regular expression