diff --git a/config/alternate_listener.xml b/config/alternate_listener.xml index 103fa4e..4c22b75 100644 --- a/config/alternate_listener.xml +++ b/config/alternate_listener.xml @@ -7,7 +7,7 @@ %presta_sitemap.alternate% - + diff --git a/config/route_annotation_listener.xml b/config/route_annotation_listener.xml index 4f126f5..a050be4 100644 --- a/config/route_annotation_listener.xml +++ b/config/route_annotation_listener.xml @@ -12,7 +12,7 @@ %presta_sitemap.default_section% - + diff --git a/src/EventListener/RouteAnnotationEventListener.php b/src/EventListener/RouteAnnotationEventListener.php index 191deda..f13beb9 100644 --- a/src/EventListener/RouteAnnotationEventListener.php +++ b/src/EventListener/RouteAnnotationEventListener.php @@ -17,7 +17,6 @@ use Presta\SitemapBundle\Service\UrlContainerInterface; use Presta\SitemapBundle\Sitemap\Url\UrlConcrete; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; @@ -28,7 +27,7 @@ * * @phpstan-import-type RouteOptions from RouteOptionParser */ -class RouteAnnotationEventListener implements EventSubscriberInterface +class RouteAnnotationEventListener { /** * @var RouterInterface @@ -55,16 +54,6 @@ public function __construct( $this->defaultSection = $defaultSection; } - /** - * @inheritdoc - */ - public static function getSubscribedEvents(): array - { - return [ - SitemapPopulateEvent::class => ['registerRouteAnnotation', 0], - ]; - } - /** * @param SitemapPopulateEvent $event */ diff --git a/src/EventListener/StaticRoutesAlternateEventListener.php b/src/EventListener/StaticRoutesAlternateEventListener.php index 6bb0e48..d0449f3 100644 --- a/src/EventListener/StaticRoutesAlternateEventListener.php +++ b/src/EventListener/StaticRoutesAlternateEventListener.php @@ -14,7 +14,6 @@ use Presta\SitemapBundle\Event\SitemapAddUrlEvent; use Presta\SitemapBundle\Sitemap\Url\GoogleMultilangUrlDecorator; use Presta\SitemapBundle\Sitemap\Url\UrlConcrete; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** @@ -28,7 +27,7 @@ * locales: array * } */ -final class StaticRoutesAlternateEventListener implements EventSubscriberInterface +final class StaticRoutesAlternateEventListener { private const TRANSLATED_ROUTE_NAME_STRATEGIES = [ 'symfony' => '/^(?P.+)\.(?P%locales%)$/', @@ -55,16 +54,6 @@ public function __construct(UrlGeneratorInterface $router, array $options) $this->options = $options; } - /** - * @inheritdoc - */ - public static function getSubscribedEvents(): array - { - return [ - SitemapAddUrlEvent::class => 'addAlternate', - ]; - } - public function addAlternate(SitemapAddUrlEvent $event): void { $name = $event->getRoute(); diff --git a/tests/Unit/DependencyInjection/PrestaSitemapExtensionTest.php b/tests/Unit/DependencyInjection/PrestaSitemapExtensionTest.php index cef1e37..c8b8005 100644 --- a/tests/Unit/DependencyInjection/PrestaSitemapExtensionTest.php +++ b/tests/Unit/DependencyInjection/PrestaSitemapExtensionTest.php @@ -27,7 +27,7 @@ class PrestaSitemapExtensionTest extends TestCase { private const SERVICES = [ - ['presta_sitemap.eventlistener.route_annotation', 'Static routes listener', 'kernel.event_subscriber'], + ['presta_sitemap.eventlistener.route_annotation', 'Static routes listener', 'kernel.event_listener'], ['presta_sitemap.controller', 'Sitemap controller', null], ['presta_sitemap.dump_command', 'Dump sitemap command', 'console.command'], ]; diff --git a/tests/Unit/EventListener/RouteAnnotationEventListenerTest.php b/tests/Unit/EventListener/RouteAnnotationEventListenerTest.php index a7b4497..d52171a 100644 --- a/tests/Unit/EventListener/RouteAnnotationEventListenerTest.php +++ b/tests/Unit/EventListener/RouteAnnotationEventListenerTest.php @@ -147,7 +147,8 @@ static function () use ($routes): RouteCollection { ['resource_type' => 'closure'] ); - $dispatcher->addSubscriber(new RouteAnnotationEventListener($router, $dispatcher, 'default')); + $listener = new RouteAnnotationEventListener($router, $dispatcher, 'default'); + $dispatcher->addListener(SitemapPopulateEvent::class, [$listener, 'registerRouteAnnotation']); $dispatcher->dispatch($event, SitemapPopulateEvent::class); } diff --git a/tests/Unit/EventListener/StaticRoutesAlternateEventListenerTest.php b/tests/Unit/EventListener/StaticRoutesAlternateEventListenerTest.php index 03dac38..1e2effc 100644 --- a/tests/Unit/EventListener/StaticRoutesAlternateEventListenerTest.php +++ b/tests/Unit/EventListener/StaticRoutesAlternateEventListenerTest.php @@ -115,8 +115,9 @@ public function untranslated(): \Generator private function dispatch(array $listenerOptions, string $route, array $options = []): SitemapAddUrlEvent { + $listener = new StaticRoutesAlternateEventListener($this->router, $listenerOptions); $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new StaticRoutesAlternateEventListener($this->router, $listenerOptions)); + $dispatcher->addListener(SitemapAddUrlEvent::class, [$listener, 'addAlternate']); $event = new SitemapAddUrlEvent($route, $options); $dispatcher->dispatch($event, SitemapAddUrlEvent::class);