示例#1
0
 /**
  * Generate unique route.
  *
  * @param RouteInterface $route
  * @param bool $withSlash
  *
  * @return null|RouteInterface
  */
 public function generateUniqueRoute(RouteInterface $route, $withSlash = false)
 {
     $originalRoutePattern = $this->generateRouteFromText($route->getRoutePattern(), $withSlash);
     if ($originalRoutePattern) {
         $key = 0;
         $routePattern = $this->normalizeRoute($originalRoutePattern);
         while ($this->hasRoute($routePattern, $route->getName())) {
             $key++;
             $routePattern = $originalRoutePattern . '-' . $key;
         }
         $route->setRoutePattern($routePattern);
         return $route;
     }
     return null;
 }
示例#2
0
 /**
  * Get unique route pattern.
  *
  * @param RouteInterface $route
  *
  * @return string
  */
 private function getUniqueRoutePattern(RouteInterface $route)
 {
     $key = 0;
     $originalRoutePattern = $this->routerHelper->normalizeRoutePattern($route->getRoutePattern());
     $routePattern = $originalRoutePattern;
     while ($this->hasRoute($route->getName(), $routePattern)) {
         $key++;
         $routePattern = $originalRoutePattern . '-' . $key;
     }
     return $routePattern;
 }