@param AbstractEvent $event
@param bool          $asynchronous

@return AbstractEvent
976942
public function publish(AbstractEvent $event, $asynchronous = false)
    {
        return $this->eventDispatcher->publish($event, $asynchronous);
    }
186427
protected function buildGlobalCodeOfEvent(AbstractEvent $event) {
        $result = '';
        if (!$event->getInline()) {
            $result .= $this->buildHandlerFunction($event);
        }
        return $result;
    }
1117863
public function registerCallback( $event, $callback ) {

		if ( !is_string( $event ) ) {
			throw new InvalidArgumentException( "Event is not a string" );
		}

		if ( !is_callable( $callback ) ) {
			throw new RuntimeException( "Invoked object is not a valid callback or Closure" );
		}

		$this->addToCollection( $event, new GenericCallbackEventListener( $callback ) );
	}
1036725
public function on($event, $callback, $priority = 0){

        if (is_array($event)) {

            foreach ($event as &$evt) {
                $this->on($evt, $callback, $priority);
            }
            return $this;
        }

        if (!isset($this->events[$event])) $this->events[$event] = [];

        // make $this available in closures
        if (is_object($callback) && $callback instanceof \Closure) {
            $callback = $callback->bindTo($this, $this);
        }

        $this->events[$event][] = ['fn' => $callback, 'prio' => $priority];

        return $this;
    }
104780
public function handleLocale(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof LocaleBehavior) {
            return;
        }

        $locale = $this->registry->getLocaleForDocument($document);
        $document->setLocale($locale);
        $document->setOriginalLocale($locale);
    }
26953
protected function getHandlerFunctionName(AbstractEvent $event) {
        $name = array_search($event, $this->handlerFunctionNames);
        if ($name === false) {
            $functionPrefix = $this->builder->getOptions()->getFunctionPrefix();
            $parts = explode('\\', get_class($event));
            $class = end($parts);
            $name = $functionPrefix . '_Handle' . $class . count($this->handlerFunctionNames);
            $this->handlerFunctionNames[$name] = $event;
        }
        return $name;
    }
916035
public function getEvent($event) : Event {
        return isset($this->registeredEvents[$event]) ? $this->registeredEvents[$event] : null;
    }
1152172
public function setEvent(EventInterface $event)
    {
        $target = $this;

        if (!($event instanceof AuthenticationEvent)) {
            $eventParams = $event->getParams();
            $eventTarget = $event->getTarget();

            if ($eventTarget) {
                $target = $eventTarget;
            }

            $event = new AuthenticationEvent();

            $event->setParams($eventParams);
        }

        $event->setIdentity(null)->setTarget($target);

        $this->event = $event;

        return $this;
    }
256713
public function addEvent(Event $event)
    {
        $this->clear();
        $this->events[$event->getName()] = $event;

        return $this;
    }
597534
@Nullable
  public static Object triggerSynchronous (@Nonnull final IEvent aEvent)
  {
    ValueEnforcer.notNull (aEvent, "Event");

    final ICommonsList <Object> aRetValues = new CommonsArrayList <> ();
    // for all scopes
    for (final EScope eCurrentScope : EScope.values ())
    {
      // get current instance of scope
      final IScope aScope = _getScope (eCurrentScope, false);
      if (aScope != null)
      {
        // get event manager (may be null)
        final InternalScopedEventManager aEventMgr = _getEventMgr (aScope);
        if (aEventMgr != null)
        {
          // main event trigger
          aRetValues.add (aEventMgr.triggerSynchronous (aEvent));
        }
      }
    }
    return aEvent.getResultAggregator ().apply (aRetValues);
  }
1072221
public function dispatch($event)
    {
        if ($event instanceof AbstractEvent) {
            $this->dispatcher->dispatch($event->getEventName(), $event);
        } else {
            $this->dispatcher->dispatch($event);
        }
        return $this;
    }
1305733
private function addEvent($event)
    {
        if (is_string($event)) {
            $event = Event::named($event);
        }

        if (!$event instanceof EventInterface) {
            throw new \InvalidArgumentException(
                'Events should be provides as Event instances or string, received type: ' . gettype($event)
            );
        }

        $this->events[] = $event;

        return $event;
    }
43697
public function setAuthorOnNode(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof LocalizedAuthorBehavior) {
            return;
        }

        // Set default value if authored is not set.
        if (null === $document->getAuthored()) {
            $document->setAuthored(new \DateTime());
        }

        $metadata = $this->metadataFactory->getMetadataForClass(get_class($document));
        if ($metadata->getSetDefaultAuthor()) {
            $this->setDefaultAuthor($document);
        }

        $encoding = 'system_localized';
        if ($document instanceof AuthorBehavior) {
            $encoding = 'system';
        } elseif (!$event->getLocale()) {
            return;
        }

        $node = $event->getNode();
        $node->setProperty(
            $this->propertyEncoder->encode($encoding, self::AUTHORED_PROPERTY_NAME, $event->getLocale()),
            $document->getAuthored()
        );
        $node->setProperty(
            $this->propertyEncoder->encode($encoding, self::AUTHOR_PROPERTY_NAME, $event->getLocale()),
            $document->getAuthor()
        );
    }
188255
public function dispatchAsyncListenersOnly($eventName, Event $event = null)
    {
        try {
            $this->asyncListener->syncMode($eventName);

            parent::dispatch($eventName, $event);
        } finally {
            $this->asyncListener->resetSyncMode();
        }
    }
347043
public function addEvent(Event $event): self
    {
        $event->setSchedule($this);
        $this->events[] = $event;

        return $this;
    }
54744
public static void triggerAsynchronous (@Nonnull final IEvent aEvent,
                                          @Nonnull final Consumer <Object> aResultCallback)
  {
    ValueEnforcer.notNull (aEvent, "Event");
    ValueEnforcer.notNull (aResultCallback, "ResultCallback");

    // for all scopes
    for (final EScope eCurrentScope : EScope.values ())
    {
      // get current instance of scope
      final IScope aScope = _getScope (eCurrentScope, false);
      if (aScope != null)
      {
        // get event manager (may be null)
        final InternalScopedEventManager aEventMgr = _getEventMgr (aScope);
        if (aEventMgr != null)
        {
          // main event trigger
          aEventMgr.triggerAsynchronous (aEvent, aResultCallback);
        }
      }
    }
  }
202747
protected function ensureEvent($event): Event
    {
        if (Assert::instanceOf($event, '\\One\\Event\\Event')) {
            return $event;
        } elseif (Assert::string($event)) {
            return new Event($event);
        }

        throw new InvalidArgumentException(
            '`Event` must be `string` or extends class `One\Event\Event`'
        );
    }