vendor/presta/sitemap-bundle/src/Event/SitemapPopulateEvent.php line 69

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the PrestaSitemapBundle package.
  4. *
  5. * (c) PrestaConcept <https://prestaconcept.net>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Presta\SitemapBundle\Event;
  11. use LogicException;
  12. use Presta\SitemapBundle\Service\UrlContainerInterface;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. use Symfony\Contracts\EventDispatcher\Event;
  15. /**
  16. * Event called whenever a sitemap build is requested.
  17. *
  18. * Subscribe to this event if :
  19. * - you want to register non-static routes
  20. */
  21. class SitemapPopulateEvent extends Event
  22. {
  23. /**
  24. * @Event("Presta\SitemapBundle\Event\SitemapPopulateEvent")
  25. * @deprecated since presta/sitemap-bundle 3.3, use `SitemapPopulateEvent::class` instead.
  26. */
  27. public const ON_SITEMAP_POPULATE = 'presta_sitemap.populate';
  28. /**
  29. * @var UrlContainerInterface
  30. */
  31. protected $urlContainer;
  32. /**
  33. * Allows creating EventListeners for particular sitemap sections, used when dumping
  34. * @var string|null
  35. */
  36. protected $section;
  37. /**
  38. * @var UrlGeneratorInterface|null
  39. */
  40. protected $urlGenerator;
  41. /**
  42. * @param UrlContainerInterface $urlContainer
  43. * @param string|null $section
  44. * @param UrlGeneratorInterface|null $urlGenerator
  45. */
  46. public function __construct(
  47. UrlContainerInterface $urlContainer,
  48. string $section = null,
  49. UrlGeneratorInterface $urlGenerator = null
  50. ) {
  51. $this->urlContainer = $urlContainer;
  52. $this->section = $section;
  53. $this->urlGenerator = $urlGenerator;
  54. }
  55. /**
  56. * @return UrlContainerInterface
  57. */
  58. public function getUrlContainer(): UrlContainerInterface
  59. {
  60. return $this->urlContainer;
  61. }
  62. /**
  63. * Section to be processed, null means any
  64. *
  65. * @return null|string
  66. */
  67. public function getSection(): ?string
  68. {
  69. return $this->section;
  70. }
  71. public function getUrlGenerator(): UrlGeneratorInterface
  72. {
  73. if (!$this->urlGenerator) {
  74. throw new LogicException('UrlGenerator was not set.');
  75. }
  76. return $this->urlGenerator;
  77. }
  78. }