Notify all observers of that a specific
event has happened

@param string|null      $event the event to trigger
@param mixed[, mixed..] $arg   the arguments to pass to the handler

@return Eden\Core\Base
180203
public function trigger($event = null)
    {
        //argument 1 must be string
        Argument::i()->test(1, 'string', 'null');

        call_user_func_array(
            array(Event::i(), 'trigger'),
            func_get_args()
        );

        return $this;
    }
1017001
public function trigger($event, $target = null, $argv = array()){
        if(!($event instanceof EventInterface)){
            $event = new Event($event, $target, $argv);
        }
        if(isset($this->listeners[$event->getName()])){
            $this->listeners[$event->getName()]->perform($event);
        }
    }
1310383
public function trigger($event, $target = null, $args = []) {
		if ($this->_profilerEnabled) {
			$profilerEvent = $this->getProfiler()->startEvent($event);
		}
		
		$this->fire($event, $target, $args);
		
		if ($this->_profilerEnabled) {
			$profilerEvent->stop();
		}
		
		return $this;
	}
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);
            }
        }
    }
1217349
public function onQuickFormEvent($event, $arg, &$caller) {
        if ($event === 'createElement') {
            if (!is_array($arg[2])) {
                $arg[2] = [];
            }
            $arg[2] += array('itemtype' => '', 'component' => '');
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
1202375
public function fireReflected(string $event, array $arguments = null) {
        return $this->getEventManager()->fireReflected($event, $arguments);
    }
1147922
private function dispatchEvent($event, $args = null)
    {
        return $this->onEventEmitterEnabled(function ($emitter) use($event, $args) {
            return $emitter->emit($event, ! is_array($args) ? [$args] : $args);
        });
    }
481654
public function notify(string $event, array $arguments = null)
    {
        if (isset($this->events[$event])) {
            foreach ($this->events[$event] as $priorityKey => $callbackKey) {
                $output = $this->subscriptions[$callbackKey]($this, $arguments ?? []);
                if (isset($output['stop']) && true === $output['stop']) {
                    break;
                }
            }
        }
    }
402476
public function trigger($event, $args = null)
    {
        if ($args === null) {
            $args = [];
        }

        settype($args, 'array');

        $prefix = XTAINJoomlaBundle::STOPWATCH_PREFIX;
        $eventUnderscore = Inflector::tableize($event);

        $beforeEvent = new BeforeEvent($args);
        self::$eventDispatcher->dispatch(self::PREFIX_BEFORE . $eventUnderscore, $beforeEvent);

        if (self::$stopwatch !== null) {
            self::$stopwatch->start($prefix . '.event.' . $eventUnderscore);
        }

        $return = parent::trigger($event, $beforeEvent->getArguments());

        if (self::$stopwatch !== null) {
            self::$stopwatch->stop($prefix . '.event.' . $eventUnderscore);
        }

        $afterEvent = new AfterEvent($args, $return);
        self::$eventDispatcher->dispatch(self::PREFIX_AFTER . $eventUnderscore, $afterEvent);

        return $afterEvent->getResult();
    }
617889
public function onQuickFormEvent($event, $arg, &$caller) {
        $this->setMoodleForm($caller);
        switch ($event) {
            case 'createElement':
                // The first argument is the name.
                $name = $arg[0];

                // Set disable actions.
                $caller->hideIf($name.'[modgrade_scale]', $name.'[modgrade_type]', 'neq', 'scale');
                $caller->hideIf($name.'[modgrade_point]', $name.'[modgrade_type]', 'neq', 'point');
                $caller->hideIf($name.'[modgrade_rescalegrades]', $name.'[modgrade_type]', 'neq', 'point');

                // Set validation rules for the sub-elements belonging to this element.
                // A handy note: the parent scope of a closure is the function in which the closure was declared.
                // Because of this using $this is safe despite the closures being called statically.
                // A nasty magic hack!
                $checkgradetypechange = function($val) {
                    // Nothing is affected by changes to the grade type if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // Check if we are changing the grade type when grades are present.
                    if (isset($val['modgrade_type']) && $val['modgrade_type'] !== $this->currentgradetype) {
                        return false;
                    }
                    return true;
                };
                $checkscalechange = function($val) {
                    // Nothing is affected by changes to the scale if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // Check if we are changing the scale type when grades are present.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'scale') {
                        if (isset($val['modgrade_scale']) && ($val['modgrade_scale'] !== $this->currentscaleid)) {
                            return false;
                        }
                    }
                    return true;
                };
                $checkmaxgradechange = function($val) {
                    // Nothing is affected by changes to the max grade if there are no grades yet.
                    if (!$this->hasgrades) {
                        return true;
                    }
                    // If we are not using ratings we can change the max grade.
                    if (!$this->useratings) {
                        return true;
                    }
                    // Check if we are changing the max grade if we are using ratings and there is a grade.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point') {
                        if (isset($val['modgrade_point']) &&
                            grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                            return false;
                        }
                    }
                    return true;
                };
                $checkmaxgrade = function($val) {
                    // Closure to validate a max points value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point') {
                        if (isset($val['modgrade_point'])) {
                            return $this->validate_point($val['modgrade_point']);
                        }
                    }
                    return true;
                };
                $checkvalidscale = function($val) {
                    // Closure to validate a scale value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'scale') {
                        if (isset($val['modgrade_scale'])) {
                            return $this->validate_scale($val['modgrade_scale']);
                        }
                    }
                    return true;
                };

                $checkrescale = function($val) {
                    // Nothing is affected by changes to grademax if there are no grades yet.
                    if (!$this->isupdate || !$this->hasgrades || !$this->canrescale) {
                        return true;
                    }
                    // Closure to validate a scale value. See the note above about scope if this confuses you.
                    // If modgrade_type is empty then use currentgradetype.
                    $gradetype = isset($val['modgrade_type']) ? $val['modgrade_type'] : $this->currentgradetype;
                    if ($gradetype === 'point' && isset($val['modgrade_point'])) {
                        // Work out if the value was actually changed in the form.
                        if (grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                            if (empty($val['modgrade_rescalegrades'])) {
                                // This was an "edit", the grademax was changed and the process existing setting was not set.
                                return false;
                            }
                        }
                    }
                    return true;
                };

                $cantchangegradetype = get_string('modgradecantchangegradetype', 'grades');
                $cantchangemaxgrade = get_string('modgradecantchangeratingmaxgrade', 'grades');
                $maxgradeexceeded = get_string('modgradeerrorbadpoint', 'grades', get_config('core', 'gradepointmax'));
                $invalidscale = get_string('modgradeerrorbadscale', 'grades');
                $cantchangescale = get_string('modgradecantchangescale', 'grades');
                $mustchooserescale = get_string('mustchooserescaleyesorno', 'grades');
                // When creating the rules the sixth arg is $force, we set it to true because otherwise the form
                // will attempt to validate the existence of the element, we don't want this because the element
                // is being created right now and doesn't actually exist as a registered element yet.
                $caller->addRule($name, $cantchangegradetype, 'callback', $checkgradetypechange, 'server', false, true);
                $caller->addRule($name, $cantchangemaxgrade, 'callback', $checkmaxgradechange, 'server', false, true);
                $caller->addRule($name, $maxgradeexceeded, 'callback', $checkmaxgrade, 'server', false, true);
                $caller->addRule($name, $invalidscale, 'callback', $checkvalidscale, 'server', false, true);
                $caller->addRule($name, $cantchangescale, 'callback', $checkscalechange, 'server', false, true);
                $caller->addRule($name, $mustchooserescale, 'callback', $checkrescale, 'server', false, true);

                break;

            case 'updateValue':
                // As this is a group element with no value of its own we are only interested in situations where the
                // default value or a constant value are being provided to the actual element.
                // In this case we expect an int that is going to translate to a scale if negative, or to max points
                // if positive.

                // Set the maximum points field to disabled if the rescale option has not been chosen and there are grades.
                $caller->disabledIf($this->getName() . '[modgrade_point]', $this->getName() .
                        '[modgrade_rescalegrades]', 'eq', '');

                // A constant value should be given as an int.
                // The default value should be an int and be either $CFG->gradepointdefault or whatever was set in set_data().
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    if ($caller->isSubmitted() && $this->_findValue($caller->_submitValues) !== null) {
                        // Submitted values are array, one value for each individual element in this group.
                        // When there is submitted data let parent::onQuickFormEvent() process it.
                        break;
                    }
                    $value = $this->_findValue($caller->_defaultValues);
                }

                if (!is_null($value) && !is_scalar($value)) {
                    // Something unexpected (likely an array of subelement values) has been given - this will be dealt
                    // with somewhere else - where exactly... likely the subelements.
                    debugging('An invalid value (type '.gettype($value).') has arrived at '.__METHOD__, DEBUG_DEVELOPER);
                    break;
                }

                // Set element state for existing data.
                // This is really a pretty hacky thing to do, when data is being set the group element is called
                // with the data first and the subelements called afterwards.
                // This means that the subelements data (inc const and default values) can be overridden by form code.
                // So - when we call this code really we can't be sure that will be the end value for the element.
                if (!empty($this->_elements)) {
                    if (!empty($value)) {
                        if ($value < 0) {
                            $this->gradetypeformelement->setValue('scale');
                            $this->scaleformelement->setValue(($value * -1));
                        } else if ($value > 0) {
                            $this->gradetypeformelement->setValue('point');
                            $maxvalue = !empty($this->currentgrade) ? (string)unformat_float($this->currentgrade) : $value;
                            $this->maxgradeformelement->setValue($maxvalue);
                        }
                    } else {
                        $this->gradetypeformelement->setValue('none');
                        $this->maxgradeformelement->setValue('');
                    }
                }
                break;
        }

        // Always let the parent do its thing!
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
1219537
public function onQuickFormEvent($event, $arg, &$caller) {
        $this->setMoodleForm($caller);
        switch ($event) {
            case 'updateValue':
                // Constant values override both default and submitted ones
                // default values are overriden by submitted.
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    // If no boxes were checked, then there is no value in the array
                    // yet we don't want to display default value in this case.
                    if ($caller->isSubmitted()) {
                        $value = $this->_findValue($caller->_submitValues);
                    } else {
                        $value = $this->_findValue($caller->_defaultValues);
                    }
                }
                if (!is_array($value)) {
                    $customize = ($value !== false || !$this->has_customize_switch());
                    if ($this->_options['type'] === 'text') {
                        $elementvalue = $customize ? $value : $this->_options['defaultvalue'];
                    } else {
                        $elementvalue = $this->timestamp_to_date_array($customize ? $value : $this->_options['defaultvalue']);
                    }
                    $value = [
                        'customize' => $customize,
                        'value' => $elementvalue
                    ];
                }
                $this->setValue($value);
                break;
            case 'createElement':
                $rv = parent::onQuickFormEvent($event, $arg, $caller);
                if ($this->has_customize_switch()) {
                    if ($this->_options['type'] === 'text') {
                        $caller->disabledIf($arg[0] . '[value]', $arg[0] . '[customize]', 'notchecked');
                    } else if ($this->_options['type'] === 'date_selector') {
                        $caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
                    } else {
                        // Date / Time selector.
                        $caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][hour]', $arg[0] . '[customize]', 'notchecked');
                        $caller->disabledIf($arg[0] . '[value][minute]', $arg[0] . '[customize]', 'notchecked');
                    }
                }
                return $rv;
            case 'addElement':
                $this->_usedcreateelement = false;
                return parent::onQuickFormEvent($event, $arg, $caller);
                break;
            default:
                return parent::onQuickFormEvent($event, $arg, $caller);
        }
    }
1241048
public function _fire($event, $args = array())
    {
        Log::d("Event " . $event, array('events'));
        global $context;
        $buffer = array();
        if (!is_array($args)) {
            $args = array($args);
        }
        if (isset($this->handlers[$event]) && count($this->handlers[$event]) > 0) {
            $handlers = $this->handlers[$event];
            foreach ($handlers as $item) {
                $result = $item->run($args);
                if ($result === true) {
                    return true;
                }
                $buffer[] = $result;
            }
            return $buffer;
        }
        return 0;
    }
1330576
public function notify($event = null)
    {
        /* @var Doozr_Base_Crud_Interface $observer */
        foreach ($this->observer as $observer) {
            $observer->update($this, $event);
        }

        $this->clear();
    }
938194
public function trigger(string $event, ...$args)
    {
        $this->getEventHandler()->trigger($event, ...$args);
        return $this;
    }
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;
    }
70214
public function trigger($event, $target = null, $argv = [])
    {
        try {
            $result = false;

            // Create event or complete
            if ($event instanceof EventInterface) {
                if (!is_null($target)) {
                    $event->setTarget($target);
                }
                if (!empty($argv)) {
                    $event->setParams($argv);
                }
            } else {
                $event = new Event($event, $target, $argv);
            }

            // Call listeners
            if (Event::validEventName($event->getName()) && isset($this->listeners[$event->getName()])) {
                // Order by priority
                usort(
                    $this->listeners[$event->getName()],
                    function ($a, $b) {
                        if ($a['priority'] == $b['priority']) {
                            return 0;
                        }

                        return ($a['priority'] < $b['priority']) ? -1 : 1;
                    });

                // Call callbacks
                foreach ($this->listeners[$event->getName()] as $listener) {
                    if (!$event->isPropagationStopped()) {
                        $result = call_user_func($listener['callback'], $event);
                    }
                }
            }

            return $result;
        } catch (\Exception $e) {
            return false;
        }
    }
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);
        }
    }