class StageEventException

Exception thrown if an error related to an event occurs.

This exception is thrown when an error strictly associated with an event occurs. This is also what makes it different from StageException.

Should not be thrown by external code.

Hierarchy

Expanded class hierarchy of StageEventException

2 files declare their use of StageEventException
ComposerPluginsValidatorTest.php in core/modules/package_manager/tests/src/Kernel/ComposerPluginsValidatorTest.php
StageBase.php in core/modules/package_manager/src/StageBase.php

File

core/modules/package_manager/src/Exception/StageEventException.php, line 18

Namespace

Drupal\package_manager\Exception
View source
class StageEventException extends StageException {
    
    /**
     * Constructs a StageEventException object.
     *
     * @param \Drupal\package_manager\Event\StageEvent $event
     *   The stage event during which this exception is thrown.
     * @param string|null $message
     *   (optional) The exception message. Defaults to a plain text representation
     *   of the validation results.
     * @param mixed ...$arguments
     *   Additional arguments to pass to the parent constructor.
     */
    public function __construct(StageEvent $event, ?string $message = NULL, ...$arguments) {
        parent::__construct($event->stage, $message ?: $this->getResultsAsText(), ...$arguments);
    }
    
    /**
     * Formats the validation results, if any, as plain text.
     *
     * @return string
     *   The results, formatted as plain text.
     */
    protected function getResultsAsText() : string {
        $text = '';
        if ($this->event instanceof PreOperationStageEvent) {
            foreach ($this->event
                ->getResults() as $result) {
                $messages = $result->messages;
                $summary = $result->summary;
                if ($summary) {
                    array_unshift($messages, $summary);
                }
                $text .= implode("\n", $messages) . "\n";
            }
        }
        return $text;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
StageEventException::getResultsAsText protected function Formats the validation results, if any, as plain text.
StageEventException::__construct public function Constructs a StageEventException object. Overrides StageException::__construct

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