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

Breadcrumb

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

class CallbackPromise

Evaluates promise callback.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

  • class \Prophecy\Promise\CallbackPromise implements \Prophecy\Promise\PromiseInterface

Expanded class hierarchy of CallbackPromise

File

vendor/phpspec/prophecy/src/Prophecy/Promise/CallbackPromise.php, line 25

Namespace

Prophecy\Promise
View source
class CallbackPromise implements PromiseInterface {
    private $callback;
    
    /**
     * Initializes callback promise.
     *
     * @param callable $callback Custom callback
     *
     * @throws \Prophecy\Exception\InvalidArgumentException
     */
    public function __construct($callback) {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException(sprintf('Callable expected as an argument to CallbackPromise, but got %s.', gettype($callback)));
        }
        $this->callback = $callback;
    }
    public function execute(array $args, ObjectProphecy $object, MethodProphecy $method) {
        $callback = $this->callback;
        if ($callback instanceof Closure && method_exists('Closure', 'bind') && (new ReflectionFunction($callback))->getClosureThis() !== null) {
            $callback = Closure::bind($callback, $object) ?? $this->callback;
        }
        return call_user_func($callback, $args, $object, $method);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CallbackPromise::$callback private property
CallbackPromise::execute public function Evaluates promise. Overrides PromiseInterface::execute
CallbackPromise::__construct public function Initializes callback promise.

API Navigation

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