本文整理匯總了PHP中Cake\Event\EventManager::on方法的典型用法代碼示例。如果您正苦於以下問題:PHP EventManager::on方法的具體用法?PHP EventManager::on怎麽用?PHP EventManager::on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Event\EventManager
的用法示例。
在下文中一共展示了EventManager::on方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: attach
/**
* {@inheritDoc}
*/
public function attach($eventName, callable $listener, $priority = 1)
{
$options = [];
$options['priority'] = $priority;
$this->eventManager->on($eventName, $options, $listener);
return $this;
}
示例2: _loadListener
/**
* Load a single event class attached to Crud.
*
* @param string $name Name
* @return \Crud\Listener\BaseListener
* @throws \Crud\Error\Exception\ListenerNotConfiguredException
* @throws \Crud\Error\Exception\MissingListenerException
*/
protected function _loadListener($name)
{
if (!isset($this->_listenerInstances[$name])) {
$config = $this->config('listeners.' . $name);
if (empty($config)) {
throw new ListenerNotConfiguredException(sprintf('Listener "%s" is not configured', $name));
}
$className = App::classname($config['className'], 'Listener', 'Listener');
if (empty($className)) {
throw new MissingListenerException('Could not find listener class: ' . $config['className']);
}
$this->_listenerInstances[$name] = new $className($this->_controller);
unset($config['className']);
$this->_listenerInstances[$name]->config($config);
$this->_eventManager->on($this->_listenerInstances[$name]);
if (is_callable([$this->_listenerInstances[$name], 'setup'])) {
$this->_listenerInstances[$name]->setup();
}
}
return $this->_listenerInstances[$name];
}
示例3: 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'));
}
示例4: on
/**
* Adds a new listener to an event.
*
* @param null $eventKey
* @param array $options
* @param null $callable
* @return void
*/
public function on($eventKey = null, $options = [], $callable = null)
{
parent::on($eventKey, $options, $callable);
if (is_object($callable)) {
$key = get_class($callable);
$this->_listenersMap[$key] = $callable;
}
}