public function detach($callable, $eventKey = null)
{
if ($callable instanceof CakeEventListener) {
return $this->_detachSubscriber($callable, $eventKey);
}
if (empty($eventKey)) {
foreach (array_keys($this->_listeners) as $eventKey) {
$this->detach($callable, $eventKey);
}
return;
}
if (empty($this->_listeners[$eventKey])) {
return;
}
foreach ($this->_listeners[$eventKey] as $priority => $callables) {
foreach ($callables as $k => $callback) {
if ($callback['callable'] === $callable) {
unset($this->_listeners[$eventKey][$priority][$k]);
break;
}
}
}
}
/** * Remove a listener from Crud. * * This will also detach it from the EventManager if it's attached. * * @param string $name * @return boolean */ public function removeListener($name) { $listeners = $this->config('listeners'); if (!array_key_exists($name, $listeners)) { return false; } if (isset($this->_listenerInstances[$name])) { $this->_eventManager->detach($this->_listenerInstances[$name]); unset($this->_listenerInstances[$name]); } unset($listeners[$name]); $this->settings['listeners'] = $listeners; }