<?php
namespace Whater\Infrastructure\ZonesBundle\Subscriber;
use Whater\Infrastructure\CommonBundle\Subscriber\AbstractBusSitemapSubscriber;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
use Presta\SitemapBundle\Sitemap\Url\GoogleMultilangUrlDecorator;
use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Whater\Application\UseCase\Zones\CommandRequest\ListTownCommand;
class SitemapTownsPagesSubscriber extends AbstractBusSitemapSubscriber
{
/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;
/**
* @param UrlGeneratorInterface $urlGenerator
*/
public function __construct(
UrlGeneratorInterface $urlGenerator
) {
$this->urlGenerator = $urlGenerator;
}
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return [
SitemapPopulateEvent::class => 'registerTownsPages',
];
}
/**
* @param SitemapPopulateEvent $event
*/
public function registerTownsPages(SitemapPopulateEvent $event)
{
$townsPage = $this->handle(new ListTownCommand(1, 500000, "name", "asc"));
$townsPage->setMaxPerPage(500000);
$towns = $townsPage->getCurrentPageResults();
foreach ($towns as $town) {
$townUrl = new UrlConcrete(
$this->urlGenerator->generate(
'web_public_town_show_by_slug',
[
'townSlug' => $town->slug()
],
UrlGeneratorInterface::ABSOLUTE_URL
),
null,
UrlConcrete::CHANGEFREQ_WEEKLY
);
$event->getUrlContainer()->addUrl(
$townUrl,
$town->country()->isoCode() . '_towns'
);
}
}
}