eee
This commit is contained in:
@@ -97,7 +97,8 @@ class ConstrictResponse extends Message implements ResponseInterface
|
|||||||
*/
|
*/
|
||||||
public function json(array $content, int $statusCode = 200): static
|
public function json(array $content, int $statusCode = 200): static
|
||||||
{
|
{
|
||||||
$this->stream->write(json_encode($content, JSON_UNESCAPED_UNICODE));
|
$encoded = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
|
||||||
|
$this->stream->write($encoded === false ? '{"error":"json encode failed"}' : $encoded);
|
||||||
return $this->withContentType(ContentType::JSON)->withStatus($statusCode);
|
return $this->withContentType(ContentType::JSON)->withStatus($statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class ArrayFormat implements IFormat
|
|||||||
*/
|
*/
|
||||||
public function call($result): ResponseInterface
|
public function call($result): ResponseInterface
|
||||||
{
|
{
|
||||||
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
$encoded = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
|
||||||
|
return $this->response->withBody(new Stream($encoded === false ? '[]' : $encoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ class MixedFormat implements IFormat
|
|||||||
return $this->response->withBody(new Stream('[object]'));
|
return $this->response->withBody(new Stream('[object]'));
|
||||||
}
|
}
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
$encoded = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
|
||||||
|
return $this->response->withBody(new Stream($encoded === false ? '[]' : $encoded));
|
||||||
} else {
|
} else {
|
||||||
return $this->response->withBody(new Stream((string)$result));
|
return $this->response->withBody(new Stream((string)$result));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user