Repository navigation
Support converting EventSubscriberInterface to AsEventListener attributes - #1094
Merged
TomasVotruba merged 2 commits intoOct 27, 2026
Merged
Conversation
TomasVotruba
force-pushed
the
tv-as-event-listener-attribute-composer-based
branch
from
October 27, 2026 20:22
be010ee to
5164842
Compare
…tributes
With this new rector, one can convert an implementation of an `EventSubscriberInterface` to attributes by using `AsEventListener`.
This rector will convert something like this:
```php
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyEventSubscriber implements EventSubscriberInterface
{
public function methodToBeCalled()
{
}
public static function getSubscribedEvents(): array
{
return ['some_event' => ['methodToBeCalled', 10]];
}
}
```
to this
```php
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
class MyEventSubscriber
{
#[AsEventListener(event: 'some_event', priority: 10)]
public function methodToBeCalled()
{
}
}
```
…event-dispatcher >=5.4 bond
TomasVotruba
force-pushed
the
tv-as-event-listener-attribute-composer-based
branch
from
October 27, 2026 20:32
5164842 to
e0c03ee
Compare
TomasVotruba
deleted the
tv-as-event-listener-attribute-composer-based
branch
October 27, 2026 20:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1081 by @rebuy-de (rebased on main) and registers the new rule in the composer-based set.
EventSubscriberToAttributeRectorconvertsEventSubscriberInterfaceimplementations to#[AsEventListener]attributesComposerPackageConstraint('symfony/event-dispatcher', '>=5.4')- the attribute is allowed on methods since Symfony 5.4config/sets/symfony/composer-based.phpunder the event-dispatcher 5.4 bondOriginal work by @rebuy-de (Martin Parsiegla), closes #1081.
ECS, PHPStan and the rule tests pass locally.