Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add removal of AsEventListener attribute when converting to EventSubscriber #588

Closed
wants to merge 1 commit into from

Conversation

stefantalen
Copy link
Contributor

@stefantalen stefantalen commented Mar 8, 2024

Current behaviour results in a mixed result when the #AsEventListener attribute has been used:

 namespace App\EventListener;

+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use App\Exception\Http\RestHttpExceptionInterface;
 use FOS\RestBundle\View\View;
 use FOS\RestBundle\View\ViewHandlerInterface;
@@ @@
 use Symfony\Component\HttpKernel\KernelEvents;

 #[AsEventListener(KernelEvents::EXCEPTION, method: 'onKernelException', priority: 10)]
-class RestExceptionListener
+class RestExceptionEventSubscriber implements EventSubscriberInterface
 {
     public function __construct(
         protected ViewHandlerInterface $viewHandler,
@@ @@
             $response = $this->viewHandler->handle($view);
             $event->setResponse($response);
         }
+    }
+    /**
+     * @return array<string, mixed>
+     */
+    public static function getSubscribedEvents(): array
+    {
+        return [KernelEvents::EXCEPTION => ['onKernelException', 10]];
     }
 }

Since the rule is there to convert a Listener to a Subscriber it makes sense to remove the attribute right?

Todo:

  • Add fixture(s)
  • Code formatting

@stefantalen
Copy link
Contributor Author

A solution has been provided in #616, closing this

@TomasVotruba
Copy link
Member

Thanks for checking 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants