Commit 0ee120f5 by Qiang Xue

refactored Component::off().

parent 06a91d62
...@@ -406,24 +406,25 @@ class Component extends Object ...@@ -406,24 +406,25 @@ class Component extends Object
public function off($name, $handler = null) public function off($name, $handler = null)
{ {
$this->ensureBehaviors(); $this->ensureBehaviors();
if (isset($this->_events[$name])) { if (empty($this->_events[$name])) {
if ($handler === null) { return false;
$this->_events[$name] = []; }
} else { if ($handler === null) {
$removed = false; unset($this->_events[$name]);
foreach ($this->_events[$name] as $i => $event) { return true;
if ($event[0] === $handler) { } else {
unset($this->_events[$name][$i]); $removed = false;
$removed = true; foreach ($this->_events[$name] as $i => $event) {
} if ($event[0] === $handler) {
} unset($this->_events[$name][$i]);
if ($removed) { $removed = true;
$this->_events[$name] = array_values($this->_events[$name]);
} }
return $removed;
} }
if ($removed) {
$this->_events[$name] = array_values($this->_events[$name]);
}
return $removed;
} }
return false;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment