public function testGetRouteCollectionForRequestEmpty() { $request = Request::create('/my/path'); $this->candidatesMock->expects($this->once())->method('getCandidates')->with($request)->will($this->returnValue(array())); $this->objectRepositoryMock->expects($this->never())->method('findByStaticPrefix'); $routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock, 'Route'); $collection = $routeProvider->getRouteCollectionForRequest($request); $this->assertInstanceOf('Symfony\\Component\\Routing\\RouteCollection', $collection); $this->assertCount(0, $collection); }
/** * {@inheritDoc} */ public function getRouteByName($name) { if (!$this->candidatesStrategy->isCandidate($name)) { throw new RouteNotFoundException(sprintf('Route "%s" is not handled by this route provider', $name)); } $route = $this->getRouteRepository()->findOneBy(array('name' => $name)); if (!$route) { throw new RouteNotFoundException("No route found for name '{$name}'"); } return $route; }
/** * {@inheritdoc} */ public function getRouteCollectionForRequest(Request $request) { $collection = new RouteCollection(); $candidates = $this->candidatesStrategy->getCandidates($request); if (0 === count($candidates)) { return $collection; } $routes = $this->routeManager->findVisibleByRoutePatterns($candidates); foreach ($routes as $route) { $collection->add($route->getName(), $route); } return $collection; }
/** * {@inheritDoc} */ public function getRoutesByNames($names = null) { if (null === $names) { return $this->getAllRoutes(); } $candidates = array(); foreach ($names as $key => $name) { if (UUIDHelper::isUUID($name) || $this->candidatesStrategy->isCandidate($name)) { $candidates[$key] = $name; } } if (!$candidates) { return array(); } /** @var $dm DocumentManager */ $dm = $this->getObjectManager(); $documents = $dm->findMany($this->className, $candidates); foreach ($documents as $key => $document) { if (UUIDHelper::isUUID($key) && !$this->candidatesStrategy->isCandidate($this->getObjectManager()->getUnitOfWork()->getDocumentId($document))) { // this uuid pointed out of our path. can only determine after fetching the document unset($documents[$key]); } if (!$document instanceof SymfonyRoute) { // we follow the logic of DocumentManager::findMany and do not throw an exception unset($documents[$key]); } } return $documents; }