/** * 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; }
/** * Return Prismic routing options instance * @param ServiceLocatorInterface $serviceLocator * @return LinkResolver */ public function createService(ServiceLocatorInterface $serviceLocator) { $linkResolver = new LinkResolver(); // A router is required to assemble urls $linkResolver->setRouter($serviceLocator->get('Router')); // Prismic Context and Api required for looking up bookmarks etc $linkResolver->setContext($serviceLocator->get('Prismic\\Context')); // Router Options are used to identify Prismic sepcific variables when composing and deconstructing routes $routingOptions = $serviceLocator->get('NetgluePrismic\\Mvc\\Router\\RouterOptions'); $linkResolver->setRouterOptions($routingOptions); /** * Routes have to be set rather than querying the router for them because * it's a pain in the ass trying to get information from the many different types of * routers/stacks. There are no interface methods to interrogate default params for example */ $config = $serviceLocator->get('Config'); $linkResolver->setRoutes($config['router']['routes']); return $linkResolver; }