CakeEventManager::_detachSubscriber PHP Method

_detachSubscriber() protected method

Auxiliary function to help detach all listeners provided by an object implementing CakeEventListener
protected _detachSubscriber ( CakeEventListener $subscriber, string $eventKey = null ) : void
$subscriber CakeEventListener the subscriber to be detached
$eventKey string optional event key name to unsubscribe the listener from
return void
    protected function _detachSubscriber(CakeEventListener $subscriber, $eventKey = null)
    {
        $events = (array) $subscriber->implementedEvents();
        if (!empty($eventKey) && empty($events[$eventKey])) {
            return;
        } elseif (!empty($eventKey)) {
            $events = array($eventKey => $events[$eventKey]);
        }
        foreach ($events as $key => $function) {
            if (is_array($function)) {
                if (is_numeric(key($function))) {
                    foreach ($function as $handler) {
                        $handler = isset($handler['callable']) ? $handler['callable'] : $handler;
                        $this->detach(array($subscriber, $handler), $key);
                    }
                    continue;
                }
                $function = $function['callable'];
            }
            $this->detach(array($subscriber, $function), $key);
        }
    }