src/Infrastructure/ZonesBundle/Subscriber/SitemapTownsPagesSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. namespace Whater\Infrastructure\ZonesBundle\Subscriber;
  3. use Whater\Infrastructure\CommonBundle\Subscriber\AbstractBusSitemapSubscriber;
  4. use Presta\SitemapBundle\Event\SitemapPopulateEvent;
  5. use Presta\SitemapBundle\Sitemap\Url\GoogleMultilangUrlDecorator;
  6. use Presta\SitemapBundle\Sitemap\Url\UrlConcrete;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  9. use Whater\Application\UseCase\Zones\CommandRequest\ListTownCommand;
  10. class SitemapTownsPagesSubscriber extends AbstractBusSitemapSubscriber
  11. {
  12. /**
  13. * @var UrlGeneratorInterface
  14. */
  15. private $urlGenerator;
  16. /**
  17. * @param UrlGeneratorInterface $urlGenerator
  18. */
  19. public function __construct(
  20. UrlGeneratorInterface $urlGenerator
  21. ) {
  22. $this->urlGenerator = $urlGenerator;
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public static function getSubscribedEvents()
  28. {
  29. return [
  30. SitemapPopulateEvent::class => 'registerTownsPages',
  31. ];
  32. }
  33. /**
  34. * @param SitemapPopulateEvent $event
  35. */
  36. public function registerTownsPages(SitemapPopulateEvent $event)
  37. {
  38. $townsPage = $this->handle(new ListTownCommand(1, 500000, "name", "asc"));
  39. $townsPage->setMaxPerPage(500000);
  40. $towns = $townsPage->getCurrentPageResults();
  41. foreach ($towns as $town) {
  42. $townUrl = new UrlConcrete(
  43. $this->urlGenerator->generate(
  44. 'web_public_town_show_by_slug',
  45. [
  46. 'townSlug' => $town->slug()
  47. ],
  48. UrlGeneratorInterface::ABSOLUTE_URL
  49. ),
  50. null,
  51. UrlConcrete::CHANGEFREQ_WEEKLY
  52. );
  53. $event->getUrlContainer()->addUrl(
  54. $townUrl,
  55. $town->country()->isoCode() . '_towns'
  56. );
  57. }
  58. }
  59. }