src/EventSubscriber/SitemapSubscriber.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Presta\SitemapBundle\Event\SitemapPopulateEvent;
  5. use Presta\SitemapBundle\Service\UrlContainerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. use Throwable;
  9. /** NOTA: No hace falta definir el servicio en el fichero services.yaml porque tiene el autowire a true. Si se hace,
  10. * se registrará dos veces y se ejecutará dos veces.
  11. */
  12. class SitemapSubscriber implements EventSubscriberInterface
  13. {
  14. public function populate(SitemapPopulateEvent $event): void
  15. {
  16. $this->registrarUrls($event->getUrlContainer(), $event->getUrlGenerator());
  17. }
  18. public function registrarUrls(UrlContainerInterface $urls, UrlGeneratorInterface $router): void
  19. {
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. public static function getSubscribedEvents(): array
  25. {
  26. return [
  27. SitemapPopulateEvent::class => 'populate',
  28. ];
  29. }
  30. }