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

Breadcrumb

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

function ThrowPromise::__construct

Initializes promise.

@phpstan-param class-string<\Throwable>|\Throwable $exception

Parameters

string|\Throwable $exception Exception class name or instance:

Throws

\Prophecy\Exception\InvalidArgumentException

File

vendor/phpspec/prophecy/src/Prophecy/Promise/ThrowPromise.php, line 43

Class

ThrowPromise
Throws predefined exception.

Namespace

Prophecy\Promise

Code

public function __construct($exception) {
    if (is_string($exception)) {
        if (!class_exists($exception) && !interface_exists($exception) || !$this->isAValidThrowable($exception)) {
            throw new InvalidArgumentException(sprintf('Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.', $exception));
        }
    }
    elseif (!$exception instanceof \Exception && !$exception instanceof \Throwable) {
        throw new InvalidArgumentException(sprintf('Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.', is_object($exception) ? get_class($exception) : gettype($exception)));
    }
    $this->exception = $exception;
}

API Navigation

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