public function setUpEnvironment() { $session = App::getSession(); if (is_null($session->getLocale())) { $session->setLocale(Locale::de_DE); } }
/** * @param ServesGetRequestData $request */ public function handle(ServesGetRequestData $request) { $locale = App::getSession()->getLocale(); $blogPostReadService = new BlogPostReadService($locale); $query = new SitemapQuery($request); $handler = new SitemapQueryHandler($blogPostReadService); $handler->handle($query); }
protected function whenHandlingRequest(HandlingRequestEvent $event) { $request = $event->getRequest(); $requestedLocale = $request->get('locale'); if (in_array($requestedLocale, Locale::ALL)) { App::getSession()->setLocale($requestedLocale); } }
public function getLocale() : string { return App::getSession()->getLocale(); }
/** * @param SitemapQuery $query */ public function handle(SitemapQuery $query) { $dom = new \DOMDocument('1.0', 'UTF-8'); $urlSet = $dom->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset'); $urlSet->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1'); $urlSet->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1'); $dom->appendChild($urlSet); $url = $dom->createElement('url'); $homeLoc = $dom->createElement('loc', App::getUrl()); $homeImage = $dom->createElement('image:image'); $homeImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/phpindd-logo.png'); $homeImageCaption = $dom->createElement('image:caption', 'PHP in DD Blog'); $homeImage->appendChild($homeImageLoc); $homeImage->appendChild($homeImageCaption); $url->appendChild($homeLoc); $url->appendChild($homeImage); $urlSet->appendChild($url); $posts = $this->blogPostReadService->getAllPosts(); foreach ($posts as $post) { $url = $dom->createElement('url'); $postLoc = $dom->createElement('loc', App::getUrl() . $post->url); $url->appendChild($postLoc); $urlSet->appendChild($url); } # hwoltersdorf $url = $dom->createElement('url'); $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/holger-woltersdorf'); $authorImage = $dom->createElement('image:image'); $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/hwoltersdorf.jpg'); $authorImageCaption = $dom->createElement('image:caption', 'Holger Woltersdorf'); $authorImage->appendChild($authorImageLoc); $authorImage->appendChild($authorImageCaption); $url->appendChild($authorLoc); $url->appendChild($authorImage); $urlSet->appendChild($url); # dmersiowsky $url = $dom->createElement('url'); $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/daniel-mersiowsky'); $authorImage = $dom->createElement('image:image'); $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/dmersiowsky.jpg'); $authorImageCaption = $dom->createElement('image:caption', 'Daniel Mersiowsky'); $authorImage->appendChild($authorImageLoc); $authorImage->appendChild($authorImageCaption); $url->appendChild($authorLoc); $url->appendChild($authorImage); $urlSet->appendChild($url); # tmissner $url = $dom->createElement('url'); $authorLoc = $dom->createElement('loc', App::getUrl() . '/about/author/tobias-missner'); $authorImage = $dom->createElement('image:image'); $authorImageLoc = $dom->createElement('image:loc', App::getUrl() . '/img/tmissner.png'); $authorImageCaption = $dom->createElement('image:caption', 'Tobias Mißner'); $authorImage->appendChild($authorImageLoc); $authorImage->appendChild($authorImageCaption); $url->appendChild($authorLoc); $url->appendChild($authorImage); $urlSet->appendChild($url); $content = $dom->saveXML(); header('Content-Type: text/xml; charset=utf-8'); header('Content-Length: ' . grapheme_strlen($content)); echo $content; }
private function getPreparedData() : array { $preparedData = array_merge($this->data, ['locales' => Locale::ALL, 'locale' => App::getSession()->getLocale(), 'ProjectUrl' => App::getUrl()]); return $preparedData; }