2
namespace GuzzleHttp\Ring\Client;
4
use GuzzleHttp\Ring\Core;
5
use GuzzleHttp\Ring\Future\CompletedFutureArray;
6
use GuzzleHttp\Ring\Future\FutureArrayInterface;
9
* Ring handler that returns a canned response or evaluated function result.
13
/** @var callable|array|FutureArrayInterface */
17
* Provide an array or future to always return the same value. Provide a
18
* callable that accepts a request object and returns an array or future
19
* to dynamically create a response.
21
* @param array|FutureArrayInterface|callable $result Mock return value.
23
public function __construct($result)
25
$this->result = $result;
28
public function __invoke(array $request)
30
Core::doSleep($request);
31
$response = is_callable($this->result)
32
? call_user_func($this->result, $request)
35
if (is_array($response)) {
36
$response = new CompletedFutureArray($response + [
41
'effective_url' => null,
43
} elseif (!$response instanceof FutureArrayInterface) {
44
throw new \InvalidArgumentException(
45
'Response must be an array or FutureArrayInterface. Found '
46
. Core::describeType($request)