1 | <?php |
||
26 | class Client implements HttpClient, HttpAsyncClient |
||
27 | { |
||
28 | /** |
||
29 | * React HTTP client. |
||
30 | * |
||
31 | * @var Client |
||
32 | */ |
||
33 | private $client; |
||
34 | |||
35 | /** |
||
36 | * React event loop. |
||
37 | * |
||
38 | * @var LoopInterface |
||
39 | */ |
||
40 | private $loop; |
||
41 | |||
42 | /** |
||
43 | * @var ResponseFactory |
||
44 | */ |
||
45 | private $responseFactory; |
||
46 | |||
47 | /** |
||
48 | * @var StreamFactory |
||
49 | */ |
||
50 | private $streamFactory; |
||
51 | |||
52 | /** |
||
53 | * Initialize the React client. |
||
54 | * |
||
55 | * @param ResponseFactory|null $responseFactory |
||
56 | * @param LoopInterface|null $loop |
||
57 | * @param ReactClient|null $client |
||
58 | * @param StreamFactory|null $streamFactory |
||
59 | */ |
||
60 | 108 | public function __construct( |
|
61 | ResponseFactory $responseFactory = null, |
||
62 | LoopInterface $loop = null, |
||
63 | ReactClient $client = null, |
||
64 | StreamFactory $streamFactory = null |
||
65 | ) { |
||
66 | 108 | if (null !== $client && null === $loop) { |
|
67 | throw new \RuntimeException( |
||
68 | 'You must give a LoopInterface instance with the Client' |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | 108 | $this->loop = $loop ?: ReactFactory::buildEventLoop(); |
|
73 | 108 | $this->client = $client ?: ReactFactory::buildHttpClient($this->loop); |
|
|
|||
74 | |||
75 | 108 | $this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find(); |
|
76 | 108 | $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); |
|
77 | 108 | } |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 53 | public function sendRequest(RequestInterface $request) |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 108 | public function sendAsyncRequest(RequestInterface $request) |
|
133 | |||
134 | /** |
||
135 | * Build a React request from the PSR7 RequestInterface. |
||
136 | * |
||
137 | * @param RequestInterface $request |
||
138 | * |
||
139 | * @return ReactRequest |
||
140 | */ |
||
141 | 108 | private function buildReactRequest(RequestInterface $request) |
|
158 | |||
159 | /** |
||
160 | * Transform a React Response to a valid PSR7 ResponseInterface instance. |
||
161 | * |
||
162 | * @param ReactResponse $response |
||
163 | * @param StreamInterface $body |
||
164 | * |
||
165 | * @return ResponseInterface |
||
166 | */ |
||
167 | 105 | private function buildResponse( |
|
181 | } |
||
182 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..