當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。