-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestRpcClient.php
More file actions
44 lines (37 loc) · 1.05 KB
/
Copy pathRestRpcClient.php
File metadata and controls
44 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace ScayTrase\Api\Rest;
use GuzzleHttp\ClientInterface;
use ScayTrase\Api\Rpc\RpcClientInterface;
class RestRpcClient implements RpcClientInterface
{
/** @var ClientInterface */
private $client;
/** @var ProtocolFactoryInterface */
private $matcher;
/**
* RestRpcClient constructor.
*
* @param ClientInterface $client
* @param ProtocolFactoryInterface $factory
*/
public function __construct(
ClientInterface $client,
ProtocolFactoryInterface $factory
) {
$this->client = $client;
$this->matcher = $factory;
}
/** {@inheritdoc} */
public function invoke($calls)
{
if (!is_array($calls)) {
$calls = [$calls];
}
$containers = [];
foreach ($calls as $call) {
$promise = $this->client->sendAsync($this->matcher->encode($call));
$containers[] = new AsyncContainer($call, $promise);
}
return new AsyncResponseCollection($containers, $this->matcher);
}
}