/** * @param Route $route * @param RouteCollectionAccessor $routes * @param array $entities [[entity plural alias, url safe class name], ...] */ protected function adjustRoutes(Route $route, RouteCollectionAccessor $routes, $entities) { $routeName = $routes->getName($route); foreach ($entities as $entity) { list($pluralAlias, $urlSafeClassName) = $entity; $existingRoute = $routes->getByPath(str_replace(self::ENTITY_PLACEHOLDER, $pluralAlias, $route->getPath()), $route->getMethods()); if ($existingRoute) { // move existing route before the current route $existingRouteName = $routes->getName($existingRoute); $routes->remove($existingRouteName); $routes->insert($existingRouteName, $existingRoute, $routeName, true); // additional route for entities which has api, but it not recognize urls like // /api/rest/latest/Oro_Bundle_AddressBundle_Entity_Country // TODO: This should be removed in scope of https://magecore.atlassian.net/browse/BAP-8650 $dictionaryRoute = $routes->cloneRoute($existingRoute); $dictionaryRoute->setPath(str_replace(self::ENTITY_PLACEHOLDER, $urlSafeClassName, $route->getPath())); $routes->insert($routes->generateRouteName($existingRouteName), $dictionaryRoute, $existingRouteName, true); } else { // add an additional strict route based on the base route and current entity $strictRoute = $routes->cloneRoute($route); $strictRoute->setPath(str_replace(self::ENTITY_PLACEHOLDER, $pluralAlias, $strictRoute->getPath())); $strictRoute->setDefault(self::ENTITY_ATTRIBUTE, $pluralAlias); $routes->insert($routes->generateRouteName($routeName), $strictRoute, $routeName, true); } } }
public function testRemoveWithAlreadyBuilderRouteMap() { $route1 = new Route('/route1'); $route2 = new Route('/route2'); $this->collection->add('route1', $route1); $this->collection->add('route2', $route2); // force the route map building $this->assertSame($route1, $this->accessor->getByPath('/route1', [])); $this->accessor->remove('route1'); $this->assertEquals(['route2'], array_keys($this->collection->all())); $this->assertNull($this->accessor->getByPath('/route1', [])); }
/** * @param Route $route * @param RouteCollectionAccessor $routes * @param string[] $activities */ protected function adjustRoutes(Route $route, RouteCollectionAccessor $routes, $activities) { $routeName = $routes->getName($route); foreach ($activities as $activity) { $existingRoute = $routes->getByPath(str_replace(self::ACTIVITY_PLACEHOLDER, $activity, $route->getPath()), $route->getMethods()); if ($existingRoute) { // move existing route before the current route $existingRouteName = $routes->getName($existingRoute); $routes->remove($existingRouteName); $routes->insert($existingRouteName, $existingRoute, $routeName, true); } else { // add an additional strict route based on the base route and current activity $strictRoute = $routes->cloneRoute($route); $strictRoute->setPath(str_replace(self::ACTIVITY_PLACEHOLDER, $activity, $strictRoute->getPath())); $strictRoute->setDefault(self::ACTIVITY_ATTRIBUTE, $activity); $this->completeRouteRequirements($strictRoute); $routes->insert($routes->generateRouteName($routeName), $strictRoute, $routeName, true); } } }
/** * @param Route $route * @param RouteCollectionAccessor $routes * @param string[] $entities * * @return string[] The list of entities handled by the default controller */ protected function adjustRoutes(Route $route, RouteCollectionAccessor $routes, $entities) { $result = []; $routeName = $routes->getName($route); foreach ($entities as $className) { $entity = $this->entityAliasResolver->getPluralAlias($className); $existingRoute = $routes->getByPath(str_replace(self::ENTITY_PLACEHOLDER, $entity, $route->getPath()), $route->getMethods()); if ($existingRoute) { // move existing route before the current route $existingRouteName = $routes->getName($existingRoute); $routes->remove($existingRouteName); $routes->insert($existingRouteName, $existingRoute, $routeName, true); } else { // add an additional strict route based on the base route and current entity $strictRoute = $routes->cloneRoute($route); $strictRoute->setPath(str_replace(self::ENTITY_PLACEHOLDER, $entity, $strictRoute->getPath())); $strictRoute->setDefault(self::ENTITY_ATTRIBUTE, $entity); $routes->insert($routes->generateRouteName($routeName), $strictRoute, $routeName, true); $result[] = $entity; $result[] = $this->entityClassNameHelper->getUrlSafeClassName($className); } } return $result; }
/** * @param Route $route * @param RouteCollectionAccessor $routes * @param string[] $entities */ protected function adjustRoutes(Route $route, RouteCollectionAccessor $routes, $entities) { $routeName = $routes->getName($route); foreach ($entities as $className) { $entity = $this->entityAliasResolver->getPluralAlias($className); if (empty($entity)) { continue; } $existingRoute = $routes->getByPath(str_replace(self::ENTITY_PLACEHOLDER, $entity, $route->getPath()), $route->getMethods()); if ($existingRoute) { // move existing route before the current route $existingRouteName = $routes->getName($existingRoute); $routes->remove($existingRouteName); $routes->insert($existingRouteName, $existingRoute, $routeName, true); } else { // add an additional strict route based on the base route and current entity $strictRoute = $routes->cloneRoute($route); $strictRoute->setPath(str_replace(self::ENTITY_PLACEHOLDER, $entity, $strictRoute->getPath())); $strictRoute->setDefault(self::ENTITY_ATTRIBUTE, $entity); $requirements = $strictRoute->getRequirements(); unset($requirements[self::ENTITY_ATTRIBUTE]); $strictRoute->setRequirements($requirements); if ($this->hasAttribute($route, self::ID_PLACEHOLDER)) { $this->setIdRequirement($strictRoute, $className); } $routes->insert($routes->generateRouteName($routeName), $strictRoute, $routeName, true); } } }