本文整理汇总了PHP中Cake\Event\EventManager::off方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::off方法的具体用法?PHP EventManager::off怎么用?PHP EventManager::off使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Event\EventManager
的用法示例。
在下文中一共展示了EventManager::off方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeListener
/**
* 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;
}
示例2: testRemoveAllListeners
/**
* 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'));
}
示例3: off
/**
* 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);
}