Skip to content

Commit 8a43c77

Browse files
committed
Remove ReactMessageFactory
Update #5
1 parent c83437a commit 8a43c77

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

src/Client.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class Client implements HttpClient, HttpAsyncClient
3434
*/
3535
private $loop;
3636

37+
/**
38+
* HttpPlug message factory
39+
* @var MessageFactory
40+
*/
41+
private $messageFactory;
42+
3743
/**
3844
* Initialize the React client
3945
* @param LoopInterface|null $loop React Event loop
@@ -54,7 +60,7 @@ public function __construct(
5460
);
5561
}
5662

57-
$this->messageFactory = new ReactMessageFactory($messageFactory);
63+
$this->messageFactory = $messageFactory;
5864
}
5965

6066
/**
@@ -94,7 +100,7 @@ public function sendAsyncRequest(RequestInterface $request)
94100

95101
$response->on('end', function (\Exception $error = null) use ($deferred, $request, $response, &$bodyStream) {
96102
$bodyStream->rewind();
97-
$psr7Response = $this->messageFactory->buildResponse(
103+
$psr7Response = $this->buildResponse(
98104
$response,
99105
$bodyStream
100106
);
@@ -142,4 +148,23 @@ private function buildReactRequest(RequestInterface $request)
142148

143149
return $reactRequest;
144150
}
151+
152+
/**
153+
* Transform a React Response to a valid PSR7 ResponseInterface instance
154+
* @param ReactResponse $response
155+
* @return ResponseInterface
156+
*/
157+
private function buildResponse(
158+
ReactResponse $response,
159+
StreamInterface $body
160+
) {
161+
$body->rewind();
162+
return $this->messageFactory->createResponse(
163+
$response->getCode(),
164+
$response->getReasonPhrase(),
165+
$response->getHeaders(),
166+
$body,
167+
$response->getVersion()
168+
);
169+
}
145170
}

src/ReactMessageFactory.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)