8000 store $this->id in local $id to avoid errors when this value is changed by pjordaan · Pull Request #9748 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

store $this->id in local $id to avoid errors when this value is changed #9748

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ private function saveInfoInProfile(Profile $profile, $updateChildren)

private function preDispatch($eventName, Event $event)
{
$id = $this->id; //the value of $this->id can change during execution of this method, so we store it in a local variable
// wrap all listeners before they are called
$this->wrappedListeners[$this->id] = new \SplObjectStorage();
$this->wrappedListeners[$id] = new \SplObjectStorage();

$listeners = $this->dispatcher->getListeners($eventName);

foreach ($listeners as $listener) {
$this->dispatcher->removeListener($eventName, $listener);
$wrapped = $this->wrapListener($eventName, $listener);
$this->wrappedListeners[$this->id][$wrapped] = $listener;
$this->wrappedListeners[$id][$wrapped] = $listener;
$this->dispatcher->addListener($eventName, $wrapped);
}

Expand Down Expand Up @@ -431,13 +432,13 @@ private function postDispatch($eventName, Event $event)
$this->updateProfiles($token, false);
break;
}

foreach ($this->wrappedListeners[$this->id] as $wrapped) {
$id = $this->id;
foreach ($this->wrappedListeners[$id] as $wrapped) {
$this->dispatcher->removeListener($eventName, $wrapped);
$this->dispatcher->addListener($eventName, $this->wrappedListeners[$this->id][$wrapped]);
$this->dispatcher->addListener($eventName, $this->wrappedListeners[$id][$wrapped]);
}

unset($this->wrappedListeners[$this->id]);
unset($this->wrappedListeners[$id]);
}

private function wrapListener($eventName, $listener)
Expand Down
0