Events::trigger PHP Метод

trigger() публичный статический Метод

Triggers an individual event.
public static trigger ( string $event_name = NULL, mixed $payload = NULL ) : void
$event_name string A string with the name of the event to trigger. Case sensitive.
$payload mixed (optional) An array to send to the event method.
Результат void
    public static function trigger($event_name = NULL, $payload = NULL)
    {
        if (empty($event_name) || !is_string($event_name) || !array_key_exists($event_name, self::$events)) {
            return;
        }
        foreach (self::$events[$event_name] as $subscriber) {
            if (strpos($subscriber['filename'], '.php') === FALSE) {
                $subscriber['filename'] .= '.php';
            }
            $file_path = Modules::file_path($subscriber['module'], $subscriber['filepath'], $subscriber['filename']);
            if (!file_exists($file_path)) {
                continue;
            }
            include_once $file_path;
            if (!class_exists($subscriber['class'])) {
                // if class doesn't exist check that the function is callable
                // could be just a helper function
                if (is_callable($subscriber['method'])) {
                    call_user_func($subscriber['method'], $payload);
                }
                continue;
            }
            $class = new $subscriber['class']();
            if (!is_callable(array($class, $subscriber['method']))) {
                unset($class);
                continue;
            }
            $class->{$subscriber['method']}($payload);
            unset($class);
        }
    }

Usage Example

 /**
  * @see TransactionManagerInterface::rollback
  */
 public function rollback()
 {
     if (!$this->transactionInProgress) {
         throw new TransactionException("No transaction is started.");
     }
     $this->Events->trigger('TransactionManager.rollback');
     $this->transactionInProgress = false;
     return $this;
 }
All Usage Examples Of Events::trigger