/**
  * Merge parameters from another match.
  *
  * @param  RouteMatch $match
  * @return RouteMatch
  */
 public function merge(RouteMatch $match)
 {
     $this->params = array_merge($this->params, $match->getParams());
     $this->length += $match->getLength();
     $this->matchedRouteName = $match->getMatchedRouteName();
     return $this;
 }
Exemple #2
0
 /**
  * match(): defined by RouteInterface interface.
  *
  * @see    \Zend\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 = [])
 {
     if (!method_exists($request, 'getUri')) {
         return;
     }
     if ($pathOffset === null) {
         $mustTerminate = true;
         $pathOffset = 0;
     } else {
         $mustTerminate = false;
     }
     if ($this->chainRoutes !== null) {
         $this->addRoutes($this->chainRoutes);
         $this->chainRoutes = null;
     }
     $match = new RouteMatch([]);
     $uri = $request->getUri();
     $pathLength = strlen($uri->getPath());
     foreach ($this->routes as $route) {
         $subMatch = $route->match($request, $pathOffset, $options);
         if ($subMatch === null) {
             return;
         }
         $match->merge($subMatch);
         $pathOffset += $subMatch->getLength();
     }
     if ($mustTerminate && $pathOffset !== $pathLength) {
         return;
     }
     return $match;
 }