Skip to content

Commit 19a2c44

Browse files
crynoboneStyleCIBottaylorotwell
authored
[2.x] Fix resolving StreamResponse callback (#1042)
* [2.x] Fix resolving `StreamResponse` callback fix #1040 Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * formatting --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0a07bc6 commit 19a2c44

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/RoadRunner/RoadRunnerClient.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ public function respond(RequestContext $context, OctaneResponse $octaneResponse)
4949
);
5050
}
5151

52-
if (
53-
($octaneResponse->response instanceof StreamedResponse) &&
54-
($responseCallback = $octaneResponse->response->getCallback()) &&
55-
((new ReflectionFunction($responseCallback))->getReturnType()?->getName() === Generator::class)
56-
) {
52+
if (($octaneResponse->response instanceof StreamedResponse) &&
53+
! is_null($responseCallback = static::resolveStreamResponseCallback($octaneResponse->response))) {
5754
$this->client->getHttpWorker()->respond(
5855
$octaneResponse->response->getStatusCode(),
5956
$responseCallback(),
@@ -66,6 +63,28 @@ public function respond(RequestContext $context, OctaneResponse $octaneResponse)
6663
$this->client->respond($this->toPsr7Response($octaneResponse->response));
6764
}
6865

66+
/**
67+
* Resolve the stream response callback from the given response.
68+
*
69+
* @param \Symfony\Component\HttpFoundation\StreamedResponse $response
70+
* @return \Closure|null
71+
*/
72+
public static function resolveStreamResponseCallback(StreamedResponse $response)
73+
{
74+
if (is_null($responseCallback = $response->getCallback())) {
75+
return null;
76+
}
77+
78+
$reflection = new ReflectionFunction($responseCallback);
79+
80+
if ($reflection->hasReturnType() === true &&
81+
in_array($reflection->getReturnType()?->getName(), [Generator::class, 'string'])) {
82+
return $responseCallback;
83+
}
84+
85+
return null;
86+
}
87+
6988
/**
7089
* Send an error message to the server.
7190
*/

0 commit comments

Comments
 (0)