function StageBase::dispatch

Dispatches an event and handles any errors that it collects.

Parameters

\Drupal\package_manager\Event\StageEvent $event: The event object.

callable|null $on_error: (optional) A callback function to call if an error occurs, before any exceptions are thrown.

Throws

\Drupal\package_manager\Exception\StageEventException If the event collects any validation errors.

4 calls to StageBase::dispatch()
StageBase::apply in core/modules/package_manager/src/StageBase.php
Applies staged changes to the active directory.
StageBase::create in core/modules/package_manager/src/StageBase.php
Copies the active code base into the stage directory.
StageBase::postApply in core/modules/package_manager/src/StageBase.php
Performs post-apply tasks.
StageBase::require in core/modules/package_manager/src/StageBase.php
Adds or updates packages in the stage directory.

File

core/modules/package_manager/src/StageBase.php, line 590

Class

StageBase
Creates and manages a stage directory in which to install or update code.

Namespace

Drupal\package_manager

Code

protected function dispatch(StageEvent $event, ?callable $on_error = NULL) : void {
    try {
        $this->eventDispatcher
            ->dispatch($event);
        if ($event instanceof PreOperationStageEvent) {
            if ($event->getResults()) {
                $error = new StageEventException($event);
            }
        }
    } catch (\Throwable $error) {
        $error = new StageEventException($event, $error->getMessage(), $error->getCode(), $error);
    }
    if (isset($error)) {
        // Ensure the error is logged for post-mortem diagnostics.
        if ($this->logger) {
            Error::logException($this->logger, $error);
        }
        if ($on_error) {
            $on_error();
        }
        throw $error;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.