Example #1
0
    /**
     * match(): defined by Route interface.
     *
     * @see    Route::match()
     * @param  Request $request
     * @return RouteMatch|null
     */
    public function match(Request $request, $pathOffset = null)
    {
        $match = $this->route->match($request, $pathOffset);

        if ($match !== null && method_exists($request, 'uri')) {
            if ($this->childRoutes !== null) {
                $this->addRoutes($this->childRoutes);
                $this->childRoutes = null;
            }
            
            $nextOffset = $pathOffset + $match->getLength();
            
            $uri  = $request->uri();
            $path = $uri->getPath();
            
            if ($this->mayTerminate && $nextOffset === strlen($path)) {
                return $match;
            }
            
            foreach ($this->children as $name => $route) {
                $subMatch = $route->match($match, $nextOffset);

                if ($subMatch !== null) {
                    return $match->merge($subMatch);
                }
            }
        }

        return null;
    }
Example #2
0
 /**
  * match(): defined by Route interface.
  *
  * @see    Route::match()
  * @param  Request $request
  * @return RouteMatch|null
  */
 public function match(Request $request, $pathOffset = null)
 {
     if ($pathOffset === null) {
         $pathOffset = 0;
     }
     $match = $this->route->match($request, $pathOffset);
     if ($match !== null && method_exists($request, 'uri')) {
         if ($this->childRoutes !== null) {
             $this->addRoutes($this->childRoutes);
             $this->childRoutes = null;
         }
         $nextOffset = $pathOffset + $match->getLength();
         $uri = $request->uri();
         $pathLength = strlen($uri->getPath());
         if ($this->mayTerminate && $nextOffset === $pathLength) {
             return $match;
         }
         foreach ($this->routes as $name => $route) {
             if (($subMatch = $route->match($request, $nextOffset)) instanceof RouteMatch) {
                 if ($match->getLength() + $subMatch->getLength() + $pathOffset === $pathLength) {
                     return $match->merge($subMatch)->setMatchedRouteName($name);
                 }
             }
         }
     }
     return null;
 }