本文整理汇总了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;
}
}