Multiton Event instance.

@param   string  $name    instance name
@param   array   $events  events array
@return  object  Event_Instance object
332855
public static function instance($name = 'fuelphp', array $events = array())
	{
		if ( ! array_key_exists($name, static::$instances))
		{
			$events = array_merge(\Config::get('event.'.$name, array()), $events);
			$instance = static::forge($events);
			static::$instances[$name] = &$instance;
		}

		return static::$instances[$name];
	}
941851
public function dispatch($event/*, string $eventName = null*/)
    {
        if (null === $this->callStack) {
            $this->callStack = new \SplObjectStorage();
        }

        $currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
        $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;

        if (\is_object($event)) {
            $eventName = $eventName ?? \get_class($event);
        } else {
            @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
            $swap = $event;
            $event = $eventName ?? new Event();
            $eventName = $swap;

            if (!$event instanceof Event) {
                throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
            }
        }

        if (null !== $this->logger && ($event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
            $this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
        }

        $this->preProcess($eventName);
        try {
            $this->beforeDispatch($eventName, $event);
            try {
                $e = $this->stopwatch->start($eventName, 'section');
                try {
                    $this->dispatcher->dispatch($event, $eventName);
                } finally {
                    if ($e->isStarted()) {
                        $e->stop();
                    }
                }
            } finally {
                $this->afterDispatch($eventName, $event);
            }
        } finally {
            $this->currentRequestHash = $currentRequestHash;
            $this->postProcess($eventName);
        }

        return $event;
    }
309302
public function triggerSubEvent($name, $event, $args = [])
    {
        return $this->getDispatcher($name)->triggerEvent($event, $args);
    }
1139123
public function triggerEvent($event)
	{
		if (!($event instanceof EventInterface))
		{
			if (isset($this->events[$event]))
			{
				$event = $this->events[$event];
			}

			else
			{
				$event = new Event($event);
			}
		}

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

				if ($listener instanceof Closure)
				{
					call_user_func($listener, $event);
				}

				else
				{
					call_user_func(array($listener, $event->getName()), $event);
				}
			}
		}

		return $event;
	}
673395
protected function newEvent(
        $eventName,
        $target = null,
        array $parameters = []
    )/*# : EventInterface */ {
        if (is_object($eventName)) {
            return $eventName;
        } else {
            return new Event($eventName, $target, $parameters);
        }
    }
199521
public function getNewActionEvent(string $name = null, $target = null, $params = null): ActionEvent
    {
        if ($name === null) {
            $name = 'action_event';
        }

        return new DefaultActionEvent($name, $target, $params);
    }
712075
public function hasEventHandlers($name)
    {
        $this->ensureBehaviors();
        return !empty($this->_events[$name]) || Event::hasHandlers($this, $name);
    }
892868
public function getDefaultEventsByEvent($name)
    {
        $events = [];

        foreach ($this->getDefaultEvents() as $event) {
            if ($event['event'] === $name) {
                $events[] = $event;
            }
        }

        return $events;
    }
561866
public function hasEventHandlers($name)
    {
        $this->ensureBehaviors();
        return !empty($this->__events__[$name]) || Event::hasHandlers($this, $name);
    }
428788
public function init(array $events)
  {
    try
    {
      $this->addEventListeners($events['listeners'])->addEventSubscribers($events['subscribers']);
    }
    catch (\Exception $e)
    {
      throw new TransformerException($e->getMessage());
    }

    return $this;
  }
613518
public function triggerAll($name, ModelEvent $event = null)
    {
        if ($event === null) {
            $event = new ModelEvent();
        }
        if ($this->triggerModels($name, $event)) {
            $this->trigger($name, $event);
        }

        return $event->isValid;
    }
434264
protected function createEvent($name, CommandInterface $command)
	{
	    $event = new ServiceEvent();
	    $event->setName($name);
	    $event->setCommand($command);
	    $event->setParams($command->getParams());

	    return $event;
	}
286255
public function getDefaultEventByName($name)
    {
        foreach ($this->getDefaultEvents() as $event) {
            if ($event['name'] === $name) {
                return $event;
            }
        }

        return null;
    }
996491
protected static function trigger($name)
    {
        if (isset(static::$_hooks[$name])) {
            $events = [];
            
            foreach (static::$_hooks[$name] as $hookEvent) {
                if ($hookEvent->isHandled) {
                    continue;
                }
                
                if (is_array($hookEvent->handler)) {
                    $hookEvent->output = call_user_func_array($hookEvent->handler, [$hookEvent]);
                } elseif (is_callable($hookEvent->handler)) {
                    $hookEvent->output = call_user_func($hookEvent->handler, $hookEvent);
                } else {
                    throw new Exception("The provided hook event handler is not valid.");
                }
                
                $hookEvent->isHandled = true;
                
                if ($hookEvent->isValid) {
                    $events[] = $hookEvent;
                }
            }

            return $events;
        }

        return [];
    }
713015
public function dispatchEvent($event, $parameters = array()) {
        if (is_string($event)) {
            $event = new BaseEvent($event, $parameters);
        }
        $eventName = $event->getName();
        $event->setDispatcher($this);
        if ($this->hasListeners($eventName)) {
            foreach($this->_listeners[$eventName] as $priority=>$listeners) {
                foreach($listeners as $listener) {
                    if ($event->isPropagationStopped($priority)) {
                        break;
                    }
                    call_user_func($listener, $event);
                }
            }
        }
        return $event;
    }
1310663
public function dispatch($eventName, Event $event = null)
    {
        if (null === $event) {
            $event = new Event();
        }

        $event->setDispatcher($this);
        $event->setName($eventName);

        if (!isset($this->listeners[$eventName])) {
            return $event;
        }

        $this->doDispatch($this->getListeners($eventName), $eventName, $event);

        return $event;
    }
415008
public function dispatch($eventName, Event $event)
    {
        if (!$this->hasListeners($eventName)) {
            return $event;
        }

        // setting event name
        $event->setName($eventName);

        // execute all callbacks for a event given
        foreach ($this->getListeners($event->getName()) as $listener) {
            call_user_func($listener, $event);

            if ($event->isPropagationStopped()) {
                break;
            }
        }

        return $event;
    }