Trigger an event.

@param   Event|string $event The event object or name.
@param   array        $args  The arguments.

@return  Event  The event after being passed through all listeners.
@throws \ReflectionException
320982
public function triggerEvent($event, $args = [])
    {
        if (!is_string($event) && !$event instanceof Event) {
            throw new \InvalidArgumentException(sprintf(
                '%s::%s only allow Event object or string.',
                get_called_class(),
                __FUNCTION__
            ));
        }

        if (!($event instanceof Event)) {
            if (isset($this->events[$event])) {
                $event = $this->events[$event];
            } else {
                $event = new Event($event);
            }
        }

        $event->mergeArguments($args);

        $listeners = [];

        if (isset($this->listeners[$event->getName()])) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                if ($event->isStopped()) {
                    return $event;
                }

                if (!is_callable($listener)) {
                    $listener = [$listener, $event->getName()];
                }

                if (!is_callable($listener)) {
                    continue;
                }

                $listener($event);

                if ($this->debug) {
                    $listeners[] = $listener;
                }
            }
        }

        if ($this->debug) {
            $executedListeners = [];

            foreach ($listeners as $listener) {
                if ($listener instanceof \Closure) {
                    $ref = new \ReflectionFunction($listener);

                    $listener = ['{Closure}: ' . $ref->getFileName() . ' - Line: ' . $ref->getStartLine()];
                }

                if (is_object($listener[0])) {
                    $listener[0] = get_class($listener[0]);
                }

                $executedListeners[] = $listener;
            }

            $this->collector[] = [
                'event' => $event->getName(),
                'listeners' => $executedListeners,
            ];
        }

        return $event;
    }
1354228
protected function triggerEvent($event)
    {
        $instance = static::cyrus();

        if (method_exists($instance, $event) &&
            in_array($event, $instance->getModelEvents())
        ) {
            $instance->{$event}($instance);
        }
    }
727367
public static function run($event, $args = array())
    {
        $config = $GLOBALS['config'];
        if (!isset($config['Hooks'])) {
            return true;
        }
        $hooks =& $config['Hooks'];

        if (!is_array($hooks) || !array_key_exists($event, $hooks) || !is_array($hooks[$event])) {
            return true;
        }

        $errorHandler = $GLOBALS['connector']->getErrorHandler();

        foreach ($hooks[$event] as $i => $hook) {

            $object = NULL;
            $method = NULL;
            $function = NULL;
            $data = NULL;
            $passData = false;

            /* $hook can be: a function, an object, an array of $functiontion and $data,
            * an array of just a function, an array of object and method, or an
            * array of object, method, and data.
            */
            //function
            if (is_string($hook)) {
                $function = $hook;
            }
            //object
            else if (is_object($hook)) {
                $object = $hooks[$event][$i];
                $method = "on" . $event;
            }
            //array of...
            else if (is_array($hook)) {
                $count = count($hook);
                if ($count) {
                    //...object
                    if (is_object($hook[0])) {
                        $object = $hooks[$event][$i][0];
                        if ($count < 2) {
                            $method = "on" . $event;
                        } else {
                            //...object and method
                            $method = $hook[1];
                            if (count($hook) > 2) {
                                //...object, method and data
                                $passData = true;
                                $data = $hook[2];
                            }
                        }
                    }
                    //...function
                    else if (is_string($hook[0])) {
                        $function = $hook[0];
                        if ($count > 1) {
                            //...function with data
                            $passData = true;
                            $data = $hook[1];
                        }
                    }
                }
            }

            /* If defined, add data to the arguments array */
            if ($passData) {
                $args = array_merge(array($data), $args);
            }

            if (isset($object)) {
                $callback = array($object, $method);
            }
            else if (false !== ($pos = strpos($function, '::'))) {
                $callback = array(substr($function, 0, $pos), substr($function, $pos + 2));
            }
            else {
                $callback = $function;
            }

            if (is_callable($callback)) {
                $ret = call_user_func_array($callback, $args);
            }
            else {
                $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback);
                $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR,
                "CKFinder failed to call a hook: " . $functionName);
                return false;
            }

            //String return is a custom error
            if (is_string($ret)) {
                $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR, $ret);
                return false;
            }
            //hook returned an error code, user error codes start from 50000
            //error codes are important because this way it is possible to create multilanguage extensions
            //TODO: two custom extensions may be popular and return the same error codes
            //recomendation: create a function that calculates the error codes starting number
            //for an extension, a pool of 100 error codes for each extension should be safe enough
            else if (is_int($ret)) {
                $errorHandler->throwError($ret);
                return false;
            }
            //no value returned
            else if( $ret === null ) {
                $functionName = CKFinder_Connector_Core_Hooks::_printCallback($callback);
                $errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_CUSTOM_ERROR,
                "CKFinder extension returned an invalid value (null)." .
                "Hook " . $functionName . " should return a value.");
                return false;
            }
            else if (!$ret) {
                return false;
            }
        }

        return true;
    }
140087
protected function dispatchEventToEventHandler($event, $arguments)
    {
        if ($this->eventHandler == null || ! method_exists($this->eventHandler, $method = "on{$event}")) {
            return;
        }

        try {
            $this->eventHandler->$method(...$arguments);
        } catch (Exception $e) {
            $this->handleException($e);
        } catch (Throwable $e) {
            $this->handleException(new FatalThrowableError($e));
        }
    }
223689
public function fire($event, $args)
    {
        $onEvent = $this->getConfig('events.'.$event);

        if ($onEvent instanceof Closure) {
            $onEvent($args);
        }
    }
965550
protected function trigger($event, ...$arguments)
    {
        if (!empty($this->handlers[$event])) {
            /** @var callable $handler */
            foreach ($this->handlers[$event] as $handler) {
                call_user_func_array($handler, $arguments);
            }
        }
    }
135416
public static function trigger($name, $args) {
        if (array_key_exists($name, static::$events)) {
            $infos = static::$events[ $name ];
            if ($infos) {
                foreach ($infos as $info) {
                    $module = Ioc::get($info[ 'class' ]);
                    if ($info[ 'action' ]) {
                        static::doAction($module, $info[ 'action' ], $args);
                    }
                }
            }
        }
    }
499237
public function triggerGroup(?array $events = [], ?array $args = null)
  {
    foreach($events as $callback) {
      if (is_callable($callback)) {
        call_user_func_array($callback, isset($args) ? $args : []);
      }
      else if (is_string($callback)) {
        $call = new $callback;
        call_user_func_array([$call, 'persist'], $args ?? []);
      }
    }
  }
933677
public function trigger($event)
    {

        if (is_string($event)) {
            $event = new Event($event);
        }
        $listeners = $this->getListeners($event->name);

        if (empty($listeners)) {
            return $event;
        }

        //print_r($listeners);

        //die;

        //Priorities... the bigger the more urgent
        $urgency = ksort($listeners, SORT_NUMERIC);
        $callbacks = array_reverse($listeners, true);

        //Loop through callbacks;
        foreach ($callbacks as $priority => $listener) {
            if ($event->isStopped()) {
                break;
            }

            foreach ($listener as $callback) {
                if ($event->isStopped()) {
                    break;
                }
                $this->propergate($event, $callback);
            }
        }

        return $event;
    }
1308059
public function trigger($event)
    {
        $result = false;
        if (isset(self::$event[$event])) {
            $result = call_user_func_array(self::$event[$event], [$this]);
        }

        return $result;
    }
1038989
protected function callListeners($event, $args = [])
    {
        if (!$this->hasListeners($event)) {
            return false;
        }

        foreach ($this->listeners[$event] as $listener) {
            $this->callListener($listener, is_array($args) ? $args : [$args]);
        }

        return true;
    }
365067
public static function trigger($event, &$data)
    {
        if (!isset(self::$manager)) {
            self::init();
        }

        return self::$manager->triggerEvent($event, $data);
    }
55475
public function fireReturn(string $event, array $arguments = null) {
        return $this->getEventManager()->fireReturn($event, $arguments);
    }
328945
public function handle($event, $args) {
		if (isset($this->callback[$event])) {
			$this->callback[$event](...$args);
		}
	}
26941
public function notify($event, array $arguments = []): void
    {
        if (!isset($this->listeners[$event])) {
            return;
        }

        foreach ($this->listeners[$event] as $listener) {
            call_user_func_array($listener, $arguments);
        }
    }
1143705
public function fire(string $event, array $arguments = null) {
        $arguments = (array)$arguments;
        foreach ($this->getBindings($event) as $callback) {
            if (is_callable($callback)) {
                call_user_func_array($callback, $arguments);
            }
        }
    }
216987
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                $caller->setType($arg[0], PARAM_INT);
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }