mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-30 01:56:35 +08:00
Fix #17223: Fixed detaching a behavior event when it is a Closure instance
This commit is contained in:
committed by
Alexander Makarov
parent
14a7198434
commit
491f9737fe
@ -27,6 +27,10 @@ class Behavior extends BaseObject
|
||||
*/
|
||||
public $owner;
|
||||
|
||||
/**
|
||||
* @var Array Attached events handlers
|
||||
*/
|
||||
private $_attachedEvents = [];
|
||||
|
||||
/**
|
||||
* Declares event handlers for the [[owner]]'s events.
|
||||
@ -72,6 +76,7 @@ class Behavior extends BaseObject
|
||||
{
|
||||
$this->owner = $owner;
|
||||
foreach ($this->events() as $event => $handler) {
|
||||
$this->_attachedEvents[$event] = $handler;
|
||||
$owner->on($event, is_string($handler) ? [$this, $handler] : $handler);
|
||||
}
|
||||
}
|
||||
@ -85,9 +90,10 @@ class Behavior extends BaseObject
|
||||
public function detach()
|
||||
{
|
||||
if ($this->owner) {
|
||||
foreach ($this->events() as $event => $handler) {
|
||||
foreach ($this->_attachedEvents as $event => $handler) {
|
||||
$this->owner->off($event, is_string($handler) ? [$this, $handler] : $handler);
|
||||
}
|
||||
$this->_attachedEvents = [];
|
||||
$this->owner = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user