/**
  * {@inheritdoc}
  */
 public function resolve(RouteInterface $route)
 {
     $i = 1;
     $path = $route->getPath();
     $conflict = $this->routeRepository->findByPath($route->getPath(), $route->getLocale());
     while ($conflict) {
         if ($conflict && $conflict->getEntityClass() === $route->getEntityClass() && $conflict->getEntityId() == $route->getEntityId()) {
             // if conflict is found but has the same entity relation return this instead of the newly created route.
             return $conflict;
         }
         $route->setPath($path . '-' . $i++);
         $conflict = $this->routeRepository->findByPath($route->getPath(), $route->getLocale());
     }
     return $route;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function update(RoutableInterface $entity, $path = null)
 {
     if (null === $entity->getRoute()) {
         throw new RouteNotCreatedException($entity);
     }
     $config = $this->getClassMappingConfiguration(get_class($entity));
     if (null === $path) {
         $path = $this->routeGenerators[$config['generator']]->generate($entity, $config['options']);
     }
     if ($path === $entity->getRoute()->getPath()) {
         return $entity->getRoute();
     }
     $route = $this->routeRepository->createNew()->setPath($path)->setEntityClass(get_class($entity))->setEntityId($entity->getId())->setLocale($entity->getLocale());
     $route = $this->conflictResolver->resolve($route);
     // path haven't changed after conflict resolving
     if ($route->getPath() === $entity->getRoute()->getPath()) {
         return $entity->getRoute();
     }
     $historyRoute = $entity->getRoute()->setHistory(true)->setTarget($route);
     $route->addHistory($historyRoute);
     foreach ($historyRoute->getHistories() as $historyRoute) {
         if ($historyRoute->getPath() === $route->getPath()) {
             // the history route will be restored
             $historyRoute->removeTarget()->setHistory(false);
             continue;
         }
         $route->addHistory($historyRoute);
         $historyRoute->setTarget($route);
     }
     $entity->setRoute($route);
     return $route;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getRouteByName($name)
 {
     if (strpos($name, self::ROUTE_PREFIX) !== 0) {
         throw new RouteNotFoundException();
     }
     $routeId = substr($name, strlen(self::ROUTE_PREFIX));
     if (array_key_exists($routeId, $this->symfonyRouteCache)) {
         return $this->symfonyRouteCache[$routeId];
     }
     /** @var RouteInterface $route */
     $route = $this->routeRepository->find($routeId);
     if (!$route || !$this->routeDefaultsProvider->supports($route->getEntityClass()) || !$this->routeDefaultsProvider->isPublished($route->getEntityClass(), $route->getEntityId(), $route->getLocale())) {
         throw new RouteNotFoundException();
     }
     return $this->createRoute($route, $this->requestStack->getCurrentRequest());
 }