Cake\Routing\RouteCollection::parse PHP Method

parse() public method

Takes the URL string and iterates the routes until one is able to parse the route.
public parse ( string $url, string $method = '' ) : array
$url string URL to parse.
$method string The HTTP method to use.
return array An array of request parameters parsed from the URL.
    public function parse($url, $method = '')
    {
        $decoded = urldecode($url);
        foreach (array_keys($this->_paths) as $path) {
            if (strpos($decoded, $path) !== 0) {
                continue;
            }
            $queryParameters = null;
            if (strpos($url, '?') !== false) {
                list($url, $queryParameters) = explode('?', $url, 2);
                parse_str($queryParameters, $queryParameters);
            }
            /* @var \Cake\Routing\Route\Route $route */
            foreach ($this->_paths[$path] as $route) {
                $r = $route->parse($url, $method);
                if ($r === false) {
                    continue;
                }
                if ($queryParameters) {
                    $r['?'] = $queryParameters;
                }
                return $r;
            }
        }
        throw new MissingRouteException(['url' => $url]);
    }

Usage Example

Beispiel #1
0
 /**
  * Parses given URL string. Returns 'routing' parameters for that URL.
  *
  * @param string $url URL to be parsed
  * @return array Parsed elements from URL
  */
 public static function parse($url)
 {
     if (!static::$initialized) {
         static::_loadRoutes();
     }
     if (strlen($url) && strpos($url, '/') !== 0) {
         $url = '/' . $url;
     }
     return static::$_routes->parse($url);
 }
All Usage Examples Of Cake\Routing\RouteCollection::parse