function SandboxManagerBase::dispatch

Dispatches an event and handles any errors that it collects.

Parameters

\Drupal\package_manager\Event\SandboxEvent $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\SandboxEventException If the event collects any validation errors.

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

File

core/modules/package_manager/src/SandboxManagerBase.php, line 618

Class

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

Namespace

Drupal\package_manager

Code

protected function dispatch(SandboxEvent $event, ?callable $on_error = NULL) : void {
  try {
    $this->eventDispatcher
      ->dispatch($event);
    if ($event instanceof SandboxValidationEvent) {
      if ($event->getResults()) {
        $error = new SandboxEventException($event);
      }
    }
  } catch (\Throwable $error) {
    $error = new SandboxEventException($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.