bug #29822 [EventDispatcher] Fix unknown priority (ro0NL)
This PR was merged into the 3.4 branch.
Discussion
----------
[EventDispatcher] Fix unknown priority
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
Somehow, after #29411 the profiler actually shows the security firewall `ContextListener`.
This listener removes itself at call time, but at this point it's wrapped reference is already in the call stack; to be displayed in the profiler.
Because the wrapped listener lazily collects its priority - it asks it from the dispatcher - we get null; the listener was already removed.
This causes the profiler to render `-` by default:
![image](https://user-images.githubusercontent.com/1047696/50850320-d5c5ee80-1379-11e9-8516-0c6bc54512ce.png)
This fixes it by always passing the expected priority at call time.
Commits
-------
9fb619ac62
[EventDispatcher] Fix unknown priority
This commit is contained in:
commit
da16b9c49b
@ -29,6 +29,7 @@ class WrappedListener
|
|||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
private $pretty;
|
private $pretty;
|
||||||
private $stub;
|
private $stub;
|
||||||
|
private $priority;
|
||||||
private static $hasClassStub;
|
private static $hasClassStub;
|
||||||
|
|
||||||
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||||
@ -96,7 +97,7 @@ class WrappedListener
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'event' => $eventName,
|
'event' => $eventName,
|
||||||
'priority' => null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null,
|
'priority' => null !== $this->priority ? $this->priority : (null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null),
|
||||||
'pretty' => $this->pretty,
|
'pretty' => $this->pretty,
|
||||||
'stub' => $this->stub,
|
'stub' => $this->stub,
|
||||||
];
|
];
|
||||||
@ -104,11 +105,14 @@ class WrappedListener
|
|||||||
|
|
||||||
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||||
{
|
{
|
||||||
|
$dispatcher = $this->dispatcher ?: $dispatcher;
|
||||||
|
|
||||||
$this->called = true;
|
$this->called = true;
|
||||||
|
$this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
|
||||||
|
|
||||||
$e = $this->stopwatch->start($this->name, 'event_listener');
|
$e = $this->stopwatch->start($this->name, 'event_listener');
|
||||||
|
|
||||||
\call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);
|
\call_user_func($this->listener, $event, $eventName, $dispatcher);
|
||||||
|
|
||||||
if ($e->isStarted()) {
|
if ($e->isStarted()) {
|
||||||
$e->stop();
|
$e->stop();
|
||||||
|
Reference in New Issue
Block a user