Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. InvalidCallbackError.php

class InvalidCallbackError

Hierarchy

  • class \Revolt\EventLoop\InvalidCallbackError extends \Revolt\EventLoop\Error

Expanded class hierarchy of InvalidCallbackError

3 files declare their use of InvalidCallbackError
AbstractDriver.php in vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php
EventLoop.php in vendor/revolt/event-loop/src/EventLoop.php
TracingDriver.php in vendor/revolt/event-loop/src/EventLoop/Driver/TracingDriver.php

File

vendor/revolt/event-loop/src/EventLoop/InvalidCallbackError.php, line 9

Namespace

Revolt\EventLoop
View source
final class InvalidCallbackError extends \Error {
    public const E_NONNULL_RETURN = 1;
    public const E_INVALID_IDENTIFIER = 2;
    
    /**
     * MUST be thrown if any callback returns a non-null value.
     */
    public static function nonNullReturn(string $callbackId, \Closure $closure) : self {
        return new self($callbackId, self::E_NONNULL_RETURN, 'Non-null return value received from callback ' . ClosureHelper::getDescription($closure));
    }
    
    /**
     * MUST be thrown if any operation (except disable() and cancel()) is attempted with an invalid callback identifier.
     *
     * An invalid callback identifier is any identifier that is not yet emitted by the driver or cancelled by the user.
     */
    public static function invalidIdentifier(string $callbackId) : self {
        return new self($callbackId, self::E_INVALID_IDENTIFIER, 'Invalid callback identifier ' . $callbackId);
    }
    
    /** @var string */
    private readonly string $rawMessage;
    
    /** @var string */
    private readonly string $callbackId;
    
    /** @var array<string, string> */
    private array $info = [];
    
    /**
     * @param string $callbackId The callback identifier.
     * @param string $message The exception message.
     */
    private function __construct(string $callbackId, int $code, string $message) {
        parent::__construct($message, $code);
        $this->callbackId = $callbackId;
        $this->rawMessage = $message;
    }
    
    /**
     * @return string The callback identifier.
     */
    public function getCallbackId() : string {
        return $this->callbackId;
    }
    public function addInfo(string $key, string $message) : void {
        $this->info[$key] = $message;
        $info = '';
        foreach ($this->info as $infoKey => $infoMessage) {
            $info .= "\r\n\r\n" . $infoKey . ': ' . $infoMessage;
        }
        $this->message = $this->rawMessage . $info;
    }

}

Members

Title Sort descending Modifiers Object type Summary
InvalidCallbackError::$callbackId private property @var string
InvalidCallbackError::$info private property @var array&lt;string, string&gt;
InvalidCallbackError::$rawMessage private property @var string
InvalidCallbackError::addInfo public function
InvalidCallbackError::E_INVALID_IDENTIFIER public constant
InvalidCallbackError::E_NONNULL_RETURN public constant
InvalidCallbackError::getCallbackId public function
InvalidCallbackError::invalidIdentifier public static function MUST be thrown if any operation (except disable() and cancel()) is attempted with an invalid callback identifier.
InvalidCallbackError::nonNullReturn public static function MUST be thrown if any callback returns a non-null value.
InvalidCallbackError::__construct private function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal