trigger() public method

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.
public trigger ( string $name, Event $event = null )
$name string the event name
$event Event the event parameter. If not set, a default [[Event]] object will be created.
コード例 #1
0
ファイル: ComponentBase.php プロジェクト: entityfx/yii2-utils
 public function triggerComponentEvent($name, Event $event, Component $component)
 {
     if ($component === null) {
         return;
     }
     $component->trigger($name, $event);
 }
コード例 #2
0
ファイル: Storage.php プロジェクト: ske/yii2-mongodb-embedded
 /**
  * @param string $name
  * @param Event $event
  */
 public function trigger($name, Event $event = null)
 {
     parent::trigger($name, $event);
     foreach ($this->_container as $model) {
         /** @var EmbeddedDocument $model */
         $model->trigger($name, $event);
     }
 }
コード例 #3
0
ファイル: Hooks.php プロジェクト: sangkilsoft/sangkilbiz-3
 /**
  * 
  * @param string|Event $event
  * @param array $params
  */
 public function fire($event)
 {
     $params = func_get_args();
     array_shift($params);
     if (is_string($event)) {
         $name = $event;
         $event = new Event($name, $params);
     } else {
         $name = $event->name;
         if ($event instanceof Event) {
             $event->params = $params;
         }
     }
     if (!in_array($name, $this->_eventStates) && ($this->maxLevel === 0 || count($this->_eventStates) < $this->maxLevel)) {
         array_push($this->_eventStates, $name);
         parent::trigger($name, $event);
         array_pop($this->_eventStates);
     }
 }
コード例 #4
0
ファイル: PluginManager.php プロジェクト: bigbrush/yii2-big
 /**
  * Triggers a plugin event.
  * This method override locates all plugins within [[group]] and automatically allows each plugin to register
  * itself as event handler in this manager.
  * 
  * If a plugin implements [[PluginInterface]] the [[PluginInterface::register()]] method is called allowing the
  * plugin to register itself as event handler in the plugin manager (or any other subclass of [[Component]]).
  *
  * Usage:
  *
  * ~~~php
  * Yii::$app->big->pluginManager->setFolder('@app/plugins')->setGroup('users')->trigger('user.saved');
  * ~~~
  *
  * @param string $name the event name.
  * @param Event $event the event parameter. If not set, a default [[Event]] object will be created.
  * @throws yii\base\InvalidConfigException if [[group]] or [[pluginsFolder]] is not set in this manager.
  */
 public function trigger($name, Event $event = null)
 {
     if (!$this->pluginsFolder) {
         throw new InvalidConfigException('The property "$pluginsFolder" must be set in ' . get_class($this) . '.');
     } elseif (!$this->group) {
         throw new InvalidConfigException('The property "$group" must be set in ' . get_class($this) . '.');
     }
     $this->activateGroup($this->group);
     parent::trigger($name, $event);
 }