Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
913 stars 137 forks source link

Enhance AsEventListener support #2282

Closed RobertMe closed 8 months ago

RobertMe commented 8 months ago

Currently #[AsEventListener] only marks methods as implicitly used when the attribute is placed on the class and has an explicit method argument. But in my experience that's not the most common usage of the attribute and both the documentation and unit tests (1, 2) show multiple possibilities, which are:

  1. #[AsEventListener] on the method itself (I believe the most common)
  2. #[AsEventListener] on the class with an explicit method specified
  3. #[AsEventListener] on a class which has an __invoke() method
  4. #[AsEventListener] on a class with an event specified but no method, in which case the method name is automatically determined based on the event name (on<event name>)

Currently only 2 is supported. This adds support for 1, 3 and 4 as well. The logic for this (including the regular expressions) is reused from Symfonys code here: https://github.com/symfony/symfony/blob/82acd7a7d6fe7a12200e949b6268ce5ba13e5e74/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php#L71-L96

Haehnchen commented 8 months ago

really nice :+1: