/** * Given a Prismic document, return an array suitable for generating a sitemap entry or null * @param Document $document * @return array|null */ protected function documentToArray(Document $document) { $type = $document->getType(); $data = array(); /** * If we can't work out the href from the link resolver, we're screwed */ $link = $this->linkGenerator->generate($document); $url = null; try { $url = $this->linkResolver->resolve($link); } catch (RoutingException $e) { // Likely, this URL needs additional parameters to be assembled } if (!$url) { return null; } $data['uri'] = $url; foreach ($this->propertyMap as $property => $fragment) { if (empty($fragment)) { continue; } $fragment = sprintf('%s.%s', $type, $fragment); $frag = $document->get($fragment); if ($frag) { $data[$property] = $frag->asText(); } } return $data; }
/** * @depends testFactoryInstance */ public function testGenerateAcceptsDocument(LinkGenerator $gen) { $link = $gen->generate($this->document); $this->assertInstanceOf('Prismic\\Fragment\\Link\\DocumentLink', $link); $this->assertSame($this->document->getId(), $link->getId()); }