Custom callback for both insert and update
@param Array $args
@param String $event
@return Void
488460
protected function _beforeSave(&$args, $event) {
        $data = &$args[1];
        if (!empty($data['url'])) {
            $url = $data['url'];
            if ($this->_isYouTubeUrl($url)) {
                // check for YouTube
                $behavior = new Garp_Model_Behavior_YouTubeable($this->_config['youtube']);
                $data['type'] = 'youtube';
            } elseif ($this->_isVimeoUrl($url)) {
                // check for Vimeo
                $behavior = new Garp_Model_Behavior_Vimeoable($this->_config['vimeo']);
                $data['type'] = 'vimeo';
            } else {
                $error = sprintf(self::ERROR_INVALID_VIDEO_URL, $url);
                throw new Garp_Model_Behavior_Videoable_Exception_InvalidUrl($error);
            }
            $behavior->{$event}($args);
        }
    }
1039764
public function emit($event, array $arguments = [])
    {
        parent::emit($event, $arguments);
        if ($this->broker) {
            $this->broker->emit($event, $arguments);
        }
    }
284131
public function event($event, ...$args){
        if($this->eventManager !== null){
            return $this->eventManager->trigger($event, $args);
        }

        return false;
    }
82128
public function triggerEvent($event, $args = [])
    {
        /** @var \Windwalker\Event\Dispatcher $dispatcher */
        $dispatcher = $this->container->get('dispatcher');

        $dispatcher->triggerEvent($event, $args);

        return $event;
    }
374451
protected function callOnListeners($event, $args = [])
    {
        $result = false;
        foreach ($this->getOnListeners($event) as $listener) {
            Helper::call($listener, $args);
        }
        return $result;
    }
253711
public function trigger(string $event, ...$args): EventInterface
    {
        $matches = $this->match($event);

        //if there are no events found
        if (empty($matches)) {
            //report a 404
            $this->meta = self::STATUS_NOT_FOUND;
            return $this;
        }

        $observers = [];
        foreach ($matches as $match) {
            $event = $match['pattern'];

            //if no direct observers
            if (!isset($this->observers[$event])) {
                continue;
            }

            //add args on to match
            $match['args'] = $args;

            //then loop the observers
            foreach ($this->observers[$event] as $observer) {
                //get the callback
                $callback = $observer['observer']->getCallback();
                $priority = $observer['priority'];
                //add on to match
                $match['callback'] = $callback;
                $observers[$priority][] = $match;
            }
        }

        //then sort by priority
        krsort($observers);
        if (!empty($observers)) {
            $observers = call_user_func_array('array_merge', $observers);
        }

        //call the callbacks
        foreach ($observers as $match) {
            //set the current
            $this->meta = $match;

            //if this is the same event, call the method, if the method returns false
            if (call_user_func_array($match['callback'], $args) === false) {
                //report a 308
                $this->meta = self::STATUS_INCOMPLETE;
                return $this;
            }
        }

        //report a 200
        $this->meta = self::STATUS_OK;

        return $this;
    }
1318055
public function emit($event, $args=null)
    {
        if (is_array($this->listeners)){
            foreach($this->listeners as $event_key => $listers_of_event){
                if ($event_key == $event){
                    foreach ($listers_of_event as $listener){
                        call_user_func($listener,$args,$event);
                    }
                }
                else {
                    $reg_exp = $this->getRegExp($event_key);
                    if ($reg_exp && preg_match($reg_exp,$event)){
                        foreach ($listers_of_event as $listener){
                            call_user_func($listener,$args,$event);
                        }
                    }
                }
            }
        }
        }
888424
public function _dispatch($event, $args = array())
    {
        if($event != "onLog") {
            Log::d("Event " . $event, array('events'));
        }
        $eventResult = new EventResult();
        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) {
                $eventResult->addHandler($item);
                $result = $item->run($args);
                if($result !== false) {
                    $eventResult->addResult($result, $item);
                }
            }
        }
        return $eventResult;
    }
592202
public function beforeUpdate(array &$args) {
        $data = &$args[1];
        foreach ($data as $key => $value) {
            /**
             * Save the current file value.
             * If it differs from the given value, it will be cleared
             * by afterUpdate.
             */
            if (in_array($key, $this->_fields)) {
                $this->_newValues[$key] = $value;
                if (!$this->_affectedRows) {
                    $model = $args[0];
                    $where = $args[2];
                    $affectedRows = $model->fetchAll($where);
                    $this->_affectedRows = $affectedRows;
                }
            }
        }
    }
60809
public function insert($arguments = [])
    {
        $ar = null;
        $ar = self::cyrus();
        /*
         | Trigger Before create events if
         | defined by user into model class
         |
         */
        $this->triggerEvent('beforeCreate');

        // Build Sql Query and prepare it
        $sql = $this->getInsertQuery(strtoupper(__FUNCTION__), $ar, $arguments);

        try {
            $statement = $this->resolveConnection()->prepare($sql);
            static::$queries[] = $statement->queryString;

            // we will bind all parameters into the statement using execute method
            if ($return = $statement->execute($arguments)) {
                $ar->{$ar->getKeyName()} = (int) $this->resolveConnection()->lastInsertId();
                /*
                 | Trigger after create events if
                 | defined by user into model class
                 |
                 */
                $this->triggerEvent('afterCreate');

                return $return;
            }
        } catch (PDOException  $exception) {
            throw new \RuntimeException($exception->getMessage());
        }
    }
811772
static public function trigger(string $event, array $args = [], bool $delete = true, $newthis = null): int {
		if(!self::exists($event)) return 0;
        

        foreach(self::$listeners[$event] as $listener) {
            static $count = 0;

            if($newthis) $listener = $listener->bindTo($newthis);
            $listener(...$args);

            $count++;
        }

        if($delete) self::delete($event);
		return $count;
	}
69932
public function trigger($events, $args = [])
    {
        $args[] = $this;
        if (!is_array($events)) {
            $events = [$events];
        }

        foreach ($events as $event) {
            dispatcher()->trigger(static::class . '.' . $event, $args);
            dispatcher()->trigger(Record::class . '.' . $event, $args);
        }

        return $this;
    }
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;
    }
1153465
public function beforeInsert(array &$args) {
        $data  = &$args[1];

        $auth = Garp_Auth::getInstance();
        if ($auth->isLoggedIn()) {
            $userData = $auth->getUserData();
            $data[self::_AUTHOR_COLUMN] = $userData['id'];
        }
    }
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;
    }
535325
public function triggerEvent($event, $args = [])
    {
        foreach ($this->dispatchers as $dispatcher) {
            $event = $dispatcher->triggerEvent($event, $args);
        }

        return $event;
    }
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);
            }
        }
    }