You are here

class CallbackPrediction in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Prediction/CallbackPrediction.php \Prophecy\Prediction\CallbackPrediction

Callback prediction.

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

Hierarchy

Expanded class hierarchy of CallbackPrediction

File

vendor/phpspec/prophecy/src/Prophecy/Prediction/CallbackPrediction.php, line 25

Namespace

Prophecy\Prediction
View source
class CallbackPrediction implements PredictionInterface {
  private $callback;

  /**
   * Initializes callback prediction.
   *
   * @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 CallbackPrediction, but got %s.', gettype($callback)));
    }
    $this->callback = $callback;
  }

  /**
   * Executes preset callback.
   *
   * @param Call[]         $calls
   * @param ObjectProphecy $object
   * @param MethodProphecy $method
   */
  public function check(array $calls, ObjectProphecy $object, MethodProphecy $method) {
    $callback = $this->callback;
    if ($callback instanceof Closure && method_exists('Closure', 'bind')) {
      $callback = Closure::bind($callback, $object);
    }
    call_user_func($callback, $calls, $object, $method);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CallbackPrediction::$callback private property
CallbackPrediction::check public function Executes preset callback. Overrides PredictionInterface::check
CallbackPrediction::__construct public function Initializes callback prediction.