Skip to content

Commit 75605b5

Browse files
committed
improve
1 parent fca3c4f commit 75605b5

File tree

6 files changed

+9
-6
lines changed

6 files changed

+9
-6
lines changed

src/Modern/DataStream/DataStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getMetadata(?string $key = null)
129129
/**
130130
* Gets or creates the inner stream by formatting the data.
131131
*/
132-
private function getFormatted(): StreamInterface
132+
public function getFormatted(): StreamInterface
133133
{
134134
if ($this->formatted !== null) {
135135
return $this->formatted;

src/Modern/Middleware/AbstractDataResponseMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ abstract class AbstractDataResponseMiddleware implements MiddlewareInterface
1818
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
1919
{
2020
$response = $handler->handle($request);
21+
2122
$body = $response->getBody();
2223
if ($body instanceof DataStream) {
2324
$body->changeFormatter($this->formatter);
25+
return $this->formatter->formatResponse($response);
2426
}
25-
return $this->formatter->formatResponse($response);
27+
28+
return $response;
2629
}
2730
}

src/Modern/ResponseFactory/HtmlResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function createResponse(
2323
int $code = Status::OK,
2424
string $reasonPhrase = '',
2525
): ResponseInterface {
26-
$body = new DataStream($data, $this->formatter);
26+
$body = (new DataStream($data, $this->formatter))->getFormatted();
2727
$response = $this->responseFactory
2828
->createResponse($code, $reasonPhrase)
2929
->withBody($body);

src/Modern/ResponseFactory/JsonResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function createResponse(
2222
int $code = Status::OK,
2323
string $reasonPhrase = '',
2424
): ResponseInterface {
25-
$body = new DataStream($data, $this->formatter);
25+
$body = (new DataStream($data, $this->formatter))->getFormatted();
2626
$response = $this->responseFactory
2727
->createResponse($code, $reasonPhrase)
2828
->withBody($body);

src/Modern/ResponseFactory/PlainTextResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function createResponse(
2323
int $code = Status::OK,
2424
string $reasonPhrase = '',
2525
): ResponseInterface {
26-
$body = new DataStream($data, $this->formatter);
26+
$body = (new DataStream($data, $this->formatter))->getFormatted();
2727
$response = $this->responseFactory
2828
->createResponse($code, $reasonPhrase)
2929
->withBody($body);

src/Modern/ResponseFactory/XmlResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function createResponse(
2222
int $code = Status::OK,
2323
string $reasonPhrase = '',
2424
): ResponseInterface {
25-
$body = new DataStream($data, $this->formatter);
25+
$body = (new DataStream($data, $this->formatter))->getFormatted();
2626
$response = $this->responseFactory
2727
->createResponse($code, $reasonPhrase)
2828
->withBody($body);

0 commit comments

Comments
 (0)