當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CakeEventManager::attach方法代碼示例

本文整理匯總了PHP中CakeEventManager::attach方法的典型用法代碼示例。如果您正苦於以下問題:PHP CakeEventManager::attach方法的具體用法?PHP CakeEventManager::attach怎麽用?PHP CakeEventManager::attach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CakeEventManager的用法示例。


在下文中一共展示了CakeEventManager::attach方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _loadListener

 /**
  * Load a single event class attached to Crud
  *
  * @param string $name
  * @return void
  */
 protected function _loadListener($name)
 {
     $subject = $this->_getSubject();
     $config = $this->config(sprintf('listenerClassMap.%s', $name));
     list($plugin, $class) = pluginSplit($config, true);
     App::uses($class, $plugin . 'Controller/Event');
     // Make sure to cleanup duplicate events
     if (isset($this->_listeners[$name])) {
         $this->_eventManager->detach($this->_listeners[$name]);
         unset($this->_listeners[$name]);
     }
     $this->_listeners[$name] = new $class($subject);
     $this->_eventManager->attach($this->_listeners[$name]);
 }
開發者ID:nodesagency,項目名稱:Platform-Crud-Plugin,代碼行數:20,代碼來源:CrudComponent.php

示例2: _loadAction

 /**
  * Load a CrudAction instance.
  *
  * @param string $name The controller action name.
  * @return CrudAction
  * @throws CakeException If action is not mapped.
  */
 protected function _loadAction($name)
 {
     if (!isset($this->_actionInstances[$name])) {
         $config = $this->config('actions.' . $name);
         if (empty($config)) {
             throw new CakeException(sprintf('Action "%s" has not been mapped', $name));
         }
         list($plugin, $class) = pluginSplit($config['className'], true);
         $class = ucfirst($class);
         if (in_array($class, array('Index', 'View', 'Add', 'Edit', 'Delete'))) {
             if (!empty($plugin) && $plugin !== 'Crud.') {
                 throw new CakeException('The build-in CrudActions (Index, View, Add, Edit and Delete) must be loaded from the Crud plugin');
             }
             $plugin = 'Crud.';
         }
         $class .= 'CrudAction';
         App::uses($class, $plugin . 'Controller/Crud/Action');
         $subject = $this->getSubject(array('action' => $name));
         $this->_actionInstances[$name] = new $class($subject, $config);
         $this->_eventManager->attach($this->_actionInstances[$name]);
     }
     return $this->_actionInstances[$name];
 }
開發者ID:sebbdk,項目名稱:booking,代碼行數:30,代碼來源:CrudComponent.php

示例3: attach

 /**
  * Adds a new listener to an event.
  * @see CakeEventManager::attach()
  * @return void
  */
 public function attach($callable, $eventKey = null, $options = array())
 {
     parent::attach($callable, $eventKey, $options);
     if (is_object($callable)) {
         $key = get_class($callable);
         $this->_listenersMap[$key] = $callable;
     }
 }
開發者ID:saydulk,項目名稱:croogo,代碼行數:13,代碼來源:CroogoEventManager.php

示例4: getEventManager

 /**
  * Returns the CakeEventManager manager instance that is handling any callbacks.
  * You can use this instance to register any new listeners or callbacks to the
  * controller events, or create your own events and trigger them at will.
  *
  * @return CakeEventManager
  */
 public function getEventManager()
 {
     if (empty($this->_eventManager)) {
         $this->_eventManager = new CakeEventManager();
         $this->_eventManager->attach($this->Components);
         $this->_eventManager->attach($this);
     }
     return $this->_eventManager;
 }
開發者ID:amysupeta,項目名稱:Exame1,代碼行數:16,代碼來源:Controller.php

示例5: _attachFilters

 /**
  * Attaches all event listeners for this dispatcher instance. Loads the
  * dispatcher filters from the configured locations.
  *
  * @param CakeEventManager $manager
  * @return void
  * @throws MissingDispatcherFilterException
  */
 protected function _attachFilters($manager)
 {
     $filters = Configure::read('Dispatcher.filters');
     if (empty($filters)) {
         return;
     }
     foreach ($filters as $filter) {
         if (is_string($filter)) {
             $filter = array('callable' => $filter);
         }
         if (is_string($filter['callable'])) {
             list($plugin, $callable) = pluginSplit($filter['callable'], true);
             App::uses($callable, $plugin . 'Routing/Filter');
             if (!class_exists($callable)) {
                 throw new MissingDispatcherFilterException($callable);
             }
             $manager->attach(new $callable());
         } else {
             $on = strtolower($filter['on']);
             $options = array();
             if (isset($filter['priority'])) {
                 $options = array('priority' => $filter['priority']);
             }
             $manager->attach($filter['callable'], 'Dispatcher.' . $on . 'Dispatch', $options);
         }
     }
 }
開發者ID:TerrasAppSolutions,項目名稱:seeg-mapbiomas-workspace,代碼行數:35,代碼來源:Dispatcher.php

示例6: getEventManager

 /**
  * Returns the CakeEventManager manager instance that is handling any callbacks.
  * You can use this instance to register any new listeners or callbacks to the
  * controller events, or create your own events and trigger them at will.
  *
  * @return CakeEventManager
  */
 public function getEventManager()
 {
     if (empty($this->_eventManager)) {
         $this->_eventManager = new CakeEventManager();
     }
     if (!$this->_eventManagerConfigured) {
         $this->_eventManager->attach($this->Helpers);
         $this->_eventManagerConfigured = true;
     }
     return $this->_eventManager;
 }
開發者ID:manzapanza,項目名稱:cakephp-api-utils,代碼行數:18,代碼來源:View.php

示例7: testStopPropagation

 /**
  * Tests that stopping an event will not notify the rest of the listeners
  *
  * @return void
  */
 public function testStopPropagation()
 {
     $manager = new CakeEventManager();
     $listener = new CakeEventTestListener();
     $manager->attach(array($listener, 'listenerFunction'), 'fake.event');
     $manager->attach(array($listener, 'stopListener'), 'fake.event', array('priority' => 8));
     $manager->attach(array($listener, 'secondListenerFunction'), 'fake.event', array('priority' => 5));
     $event = new CakeEvent('fake.event');
     $manager->dispatch($event);
     $expected = array('secondListenerFunction');
     $this->assertEquals($expected, $listener->callStack);
 }
開發者ID:julkar9,項目名稱:gss,代碼行數:17,代碼來源:CakeEventManagerTest.php

示例8: testDispatchWithGlobalAndLocalEvents

 /**
  * Test that events are dispatched properly when there are global and local
  * listeners at the same priority.
  *
  * @return void
  */
 public function testDispatchWithGlobalAndLocalEvents()
 {
     $listener = new CustomTestEventListener();
     CakeEventManager::instance()->attach($listener);
     $listener2 = new CakeEventTestListener();
     $manager = new CakeEventManager();
     $manager->attach(array($listener2, 'listenerFunction'), 'fake.event');
     $manager->dispatch(new CakeEvent('fake.event', $this));
     $this->assertEquals(array('listenerFunction'), $listener->callStack);
     $this->assertEquals(array('listenerFunction'), $listener2->callStack);
 }
開發者ID:4Queen,項目名稱:php-buildpack,代碼行數:17,代碼來源:CakeEventManagerTest.php


注:本文中的CakeEventManager::attach方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。