当前位置: 首页>>代码示例>>PHP>>正文


PHP EventManager::on方法代码示例

本文整理汇总了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;
 }
开发者ID:amir20202000,项目名称:penny,代码行数:10,代码来源:CakeEvmProxy.php

示例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];
 }
开发者ID:i3i2ain,项目名称:crud,代码行数:29,代码来源:CrudComponent.php

示例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'));
 }
开发者ID:Slayug,项目名称:castor,代码行数:13,代码来源:EventManagerTest.php

示例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;
     }
 }
开发者ID:Cheren,项目名称:union,代码行数:16,代码来源:EventManager.php


注:本文中的Cake\Event\EventManager::on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。