public function testRouteRequiresGenerator() { $expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage()); $urlGeneratorRegistry = new UrlGeneratorRegistry(); $linkFactory = new LinkFactory($expressionEvaluator, $urlGeneratorRegistry); $this->setExpectedException('RuntimeException', 'You cannot use a route without an url generator.'); $linkFactory->createLink(new TestedObject(), new Relation('foo', new Route('/route', array('foo' => 'bar')))); }
/** * @param object $object * @param SerializationContext $context * * @return Link[] */ public function createLinks($object, SerializationContext $context) { $links = array(); foreach ($this->relationsRepository->getRelations($object) as $relation) { if ($this->exclusionManager->shouldSkipLink($object, $relation, $context)) { continue; } $links[] = $this->linkFactory->createLink($object, $relation); } return $links; }
/** * @param object $object * @param string $rel * @param boolean $absolute * * @return string */ public function getLinkHref($object, $rel, $absolute = false) { foreach ($this->relationsRepository->getRelations($object) as $relation) { if ($rel === $relation->getName()) { $relation = $this->patchAbsolute($relation, $absolute); if (null !== ($link = $this->linkFactory->createLink($object, $relation))) { return $link->getHref(); } } } return null; }