upgrade zend (#1559)
[openemr.git] / vendor / phpspec / prophecy / src / Prophecy / Promise / CallbackPromise.php
blob5f406bf7a8ce0fb67dddaf1a66308e6467df904c
1 <?php
3 /*
4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Promise;
14 use Prophecy\Prophecy\ObjectProphecy;
15 use Prophecy\Prophecy\MethodProphecy;
16 use Prophecy\Exception\InvalidArgumentException;
17 use Closure;
19 /**
20 * Callback promise.
22 * @author Konstantin Kudryashov <ever.zet@gmail.com>
24 class CallbackPromise implements PromiseInterface
26 private $callback;
28 /**
29 * Initializes callback promise.
31 * @param callable $callback Custom callback
33 * @throws \Prophecy\Exception\InvalidArgumentException
35 public function __construct($callback)
37 if (!is_callable($callback)) {
38 throw new InvalidArgumentException(sprintf(
39 'Callable expected as an argument to CallbackPromise, but got %s.',
40 gettype($callback)
41 ));
44 $this->callback = $callback;
47 /**
48 * Evaluates promise callback.
50 * @param array $args
51 * @param ObjectProphecy $object
52 * @param MethodProphecy $method
54 * @return mixed
56 public function execute(array $args, ObjectProphecy $object, MethodProphecy $method)
58 $callback = $this->callback;
60 if ($callback instanceof Closure && method_exists('Closure', 'bind')) {
61 $callback = Closure::bind($callback, $object);
64 return call_user_func($callback, $args, $object, $method);