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


PHP EventManager::attach方法代码示例

本文整理汇总了PHP中Cake\Event\EventManager::attach方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::attach方法的具体用法?PHP EventManager::attach怎么用?PHP EventManager::attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Event\EventManager的用法示例。


在下文中一共展示了EventManager::attach方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set

 /**
  * Set an object directly into the registry by name.
  *
  * If this collection implements events, the passed object will
  * be attached into the event manager
  *
  * @param string $objectName The name of the object to set in the registry.
  * @param object $object instance to store in the registry
  * @return void
  */
 public function set($objectName, $object)
 {
     list($plugin, $name) = pluginSplit($objectName);
     $this->unload($objectName);
     if (isset($this->_eventManager)) {
         $this->_eventManager->attach($object);
     }
     $this->_loaded[$name] = $object;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:19,代码来源:ObjectRegistry.php

示例2: _create

 /**
  * Create the behavior instance.
  *
  * Part of the template method for Cake\Utility\ObjectRegistry::load()
  * Enabled behaviors will be registered with the event manager.
  *
  * @param string $class The classname that is missing.
  * @param string $alias The alias of the object.
  * @param array $config An array of config to use for the behavior.
  * @return Behavior The constructed behavior class.
  */
 protected function _create($class, $alias, $config)
 {
     $instance = new $class($this->_table, $config);
     $enable = isset($config['enabled']) ? $config['enabled'] : true;
     if ($enable) {
         $this->_eventManager->attach($instance);
     }
     $methods = $this->_getMethods($instance, $class, $alias);
     $this->_methodMap += $methods['methods'];
     $this->_finderMap += $methods['finders'];
     return $instance;
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:23,代码来源:BehaviorRegistry.php

示例3: 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();
     EventManager::instance()->attach($listener);
     $listener2 = new EventTestListener();
     $manager = new EventManager();
     $manager->attach(array($listener2, 'listenerFunction'), 'fake.event');
     $manager->dispatch(new Event('fake.event', $this));
     $this->assertEquals(array('listenerFunction'), $listener->callStack);
     $this->assertEquals(array('listenerFunction'), $listener2->callStack);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:17,代码来源:EventManagerTest.php

示例4: _attachFilters

 /**
  * Attaches all event listeners for this dispatcher instance. Loads the
  * dispatcher filters from the configured locations.
  *
  * @param \Cake\Event\EventManager $manager
  * @return void
  * @throws \Cake\Routing\Error\MissingDispatcherFilterException
  */
 protected function _attachFilters($manager)
 {
     $filters = Configure::read('Dispatcher.filters');
     if (empty($filters)) {
         return;
     }
     foreach ($filters as $index => $filter) {
         $settings = array();
         if (is_array($filter) && !is_int($index)) {
             $settings = $filter;
             $filter = $index;
         }
         if (is_string($filter)) {
             $filter = array('callable' => $filter);
         }
         if (is_string($filter['callable'])) {
             $callable = App::classname($filter['callable'], 'Routing/Filter');
             if (!$callable) {
                 throw new Error\MissingDispatcherFilterException($filter['callable']);
             }
             $manager->attach(new $callable($settings));
         } 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:ripzappa0924,项目名称:carte0.0.1,代码行数:39,代码来源:Dispatcher.php

示例5: __construct

 /**
  * Initializes a new instance
  *
  * The $config array understands the following keys:
  *
  * - table: Name of the database table to represent
  * - alias: Alias to be assigned to this table (default to table name)
  * - connection: The connection instance to use
  * - entityClass: The fully namespaced class name of the entity class that will
  *   represent rows in this table.
  * - schema: A \Cake\Database\Schema\Table object or an array that can be
  *   passed to it.
  * - eventManager: An instance of an event manager to use for internal events
  * - behaviors: A BehaviorRegistry. Generally not used outside of tests.
  * - associations: An Associations instance.
  *
  * @param array $config List of options for this table
  */
 public function __construct(array $config = [])
 {
     if (!empty($config['table'])) {
         $this->table($config['table']);
     }
     if (!empty($config['alias'])) {
         $this->alias($config['alias']);
     }
     if (!empty($config['connection'])) {
         $this->connection($config['connection']);
     }
     if (!empty($config['schema'])) {
         $this->schema($config['schema']);
     }
     if (!empty($config['entityClass'])) {
         $this->entityClass($config['entityClass']);
     }
     $eventManager = $behaviors = $associations = null;
     if (!empty($config['eventManager'])) {
         $eventManager = $config['eventManager'];
     }
     if (!empty($config['behaviors'])) {
         $behaviors = $config['behaviors'];
     }
     if (!empty($config['associations'])) {
         $associations = $config['associations'];
     }
     $this->_eventManager = $eventManager ?: new EventManager();
     $this->_behaviors = $behaviors ?: new BehaviorRegistry($this);
     $this->_associations = $associations ?: new Associations();
     $this->initialize($config);
     $this->_eventManager->attach($this);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:51,代码来源:Table.php


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