Пример #1
0
 public function testMatchedRouteNameIsOverridenOnMerge()
 {
     $match = new RouteMatch(array());
     $match->setMatchedRouteName('foo');
     $subMatch = new RouteMatch(array());
     $subMatch->setMatchedRouteName('bar');
     $match->merge($subMatch);
     $this->assertEquals('bar', $match->getMatchedRouteName());
 }
Пример #2
0
 /**
  * match(): defined by RouteInterface interface.
  *
  * @see    \Zend\Mvc\Router\RouteInterface::match()
  * @param  Request  $request
  * @param  int|null $pathOffset
  * @param  array    $options
  * @return RouteMatch|null
  */
 public function match(Request $request, $pathOffset = null, array $options = array())
 {
     if (!method_exists($request, 'getUri')) {
         return null;
     }
     if ($pathOffset === null) {
         $mustTerminate = true;
         $pathOffset = 0;
     } else {
         $mustTerminate = false;
     }
     if ($this->chainRoutes !== null) {
         $this->addRoutes($this->chainRoutes);
         $this->chainRoutes = null;
     }
     $match = new RouteMatch(array());
     $uri = $request->getUri();
     $pathLength = strlen($uri->getPath());
     foreach ($this->routes as $route) {
         $subMatch = $route->match($request, $pathOffset, $options);
         if ($subMatch === null) {
             return null;
         }
         $match->merge($subMatch);
         $pathOffset += $subMatch->getLength();
     }
     if ($mustTerminate && $pathOffset !== $pathLength) {
         return null;
     }
     return $match;
 }