Commit b2f6aba
committed
bug #62184 [EventDispatcher][FrameworkBundle] Rework union types on
This PR was merged into the 7.4 branch.
Discussion
----------
[EventDispatcher][FrameworkBundle] Rework union types on `#[AsEventListener]`
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
This is a reimplementation of #61252.
The previous PR introduced a backward compatibility break.
Consider the following listener:
```php
final class TestListener
{
#[AsEventListener(event: RequestEvent::class)]
public function onRequestEvent(): void
{
// ...
}
}
```
In earlier versions, this worked fine, but now it throws:
> AsEventListener attribute requires the first argument of "App\EventListener\TestListener::onRequestEvent()" to be an event object.
Interestingly, there *was* a test for this scenario, but since each test method re-defines the `registerAttributeForAutoconfiguration()` closure (which wasn't updated everywhere), the tests still passed.
Additionally, the implementation was added to the `FrameworkExtension`, even though similar logic already existed in `RegisterListenersPass::getEventFromTypeDeclaration()`, resulting in a decentralized implementation.
This PR reverts the changes in `FrameworkExtension` and re-implements the feature in `RegisterListenersPass`.
The tests now reuse the closure from `FrameworkExtension` to make them more robust and consistent with the actual implementation.
Commits
-------
8ea7196e9c9 [EventDispatcher][FrameworkBundle] Rework union types on `#[AsEventListener]`#[AsEventListener] (HypeMC)1 file changed
+5
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
806 | 785 | | |
| 786 | + | |
807 | 787 | | |
| 788 | + | |
808 | 789 | | |
809 | 790 | | |
810 | 791 | | |
| |||
0 commit comments