Library/Think/Http/Route.class.php
/**
     * Matches URI?
     *
     * Parse this route's pattern, and then compare it to an HTTP resource URI
     * This method was modeled after the techniques demonstrated by Dan Sosedoff at:
     *
     * http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/
     *
     * @param  string $resourceUri A Request URI
     * @return bool
     */
Matches URI.
Parse this route's pattern, and then compare it to an HTTP resource URI
This method was modeled after the techniques demonstrated by Dan Sosedoff at.



@param  string $resourceUri A Request URI
@return bool
Matches URI . Parse this route ' s pattern and then compare it to an HTTP resource URI This method was modeled after the techniques demonstrated by Dan Sosedoff at . @param string $resourceUri A Request URI @return bool
public function matches($resourceUri) {
        $patternAsRegex = preg_replace_callback(
            '#:([\w]+)\+?#',
            [$this, 'matchesCallback'],
            str_replace(')', ')?', (string) $this->pattern)
        );
        if (substr($this->pattern, -1) === '/') {
            $patternAsRegex .= '?';
        }
        $regex = '#^' . $patternAsRegex . '$#';
        if ($this->caseSensitive === false) {
            $regex .= 'i';
        }
        if (!preg_match($regex, $resourceUri, $paramValues)) {
            return false;
        }
        foreach ($this->paramNames as $name) {
            if (isset($paramValues[$name])) {
                if (isset($this->paramNamesPath[$name])) {
                    $this->params[$name] = explode('/', urldecode($paramValues[$name]));
                } else {
                    $this->params[$name] = urldecode($paramValues[$name]);
                }
            }
        }
        return true;
    }
public function matches ( $ resourceUri ) { $ patternAsRegex = preg_replace_callback ( '#:([\w]+)\+?#' , [ $ this , 'matchesCallback' ] , str_replace ( ')' , ')?' , ( string ) $ this -> pattern ) ) ; if ( substr ( $ this -> pattern , - 1 ) === '/' ) { $ patternAsRegex .= '?' ; } $ regex = '#^' . $ patternAsRegex . '$#' ; if ( $ this -> caseSensitive === false ) { $ regex .= 'i' ; } if ( ! preg_match ( $ regex , $ resourceUri , $ paramValues ) ) { return false ; } foreach ( $ this -> paramNames as $ name ) { if ( isset ( $ paramValues [ $ name ] ) ) { if ( isset ( $ this -> paramNamesPath [ $ name ] ) ) { $ this -> params [ $ name ] = explode ( '/' , urldecode ( $ paramValues [ $ name ] ) ) ; } else { $ this -> params [ $ name ] = urldecode ( $ paramValues [ $ name ] ) ; } } } return true ; }
Matches URI?
Matches URI?
//Convert URL params into regex patterns, construct a regex for this route, init params //Cache URL params' names and values if this route matches the current HTTP request