/** * Remove a listener from Crud. * * This will also detach it from the EventManager if it's attached. * * @param string $name Name * @return bool */ public function removeListener($name) { $listeners = $this->config('listeners'); if (!array_key_exists($name, $listeners)) { return false; } if (isset($this->_listenerInstances[$name])) { $this->_eventManager->off($this->_listenerInstances[$name]); unset($this->_listenerInstances[$name]); } unset($listeners[$name]); $this->_config['listeners'] = $listeners; }
/** * Tests off'ing all listeners for an event */ public function testRemoveAllListeners() { $manager = new EventManager(); $manager->on('fake.event', ['AClass', 'aMethod']); $manager->on('another.event', ['priority' => 1], 'fakeFunction'); $manager->off('fake.event'); $expected = [['callable' => 'fakeFunction']]; $this->assertEquals($expected, $manager->listeners('another.event')); $this->assertEquals([], $manager->listeners('fake.event')); }
/** * Removes a listener from the active listeners. * * @param \Cake\Event\EventListenerInterface|string $eventKey * @param null $callable * @return void */ public function off($eventKey, $callable = null) { if (is_object($callable)) { $key = get_class($callable); unset($this->_listenersMap[$key]); } parent::off($eventKey, $callable); }