File tree Expand file tree Collapse file tree 4 files changed +8
-4
lines changed
Expand file tree Collapse file tree 4 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 55namespace Tempest \Http ;
66
77use Generator ;
8+ use JsonSerializable ;
89use Tempest \View \View ;
910
1011final class GenericResponse implements Response
@@ -13,7 +14,7 @@ final class GenericResponse implements Response
1314
1415 public function __construct (
1516 Status $ status ,
16- Generator |View |string |array |null $ body = null ,
17+ Generator |View |string |array |JsonSerializable | null $ body = null ,
1718 array $ headers = [],
1819 ?View $ view = null ,
1920 ) {
Original file line number Diff line number Diff line change 55namespace Tempest \Http ;
66
77use Generator ;
8+ use JsonSerializable ;
89use Tempest \Http \Cookie \Cookie ;
910use Tempest \Http \Cookie \CookieManager ;
1011use Tempest \Http \Session \Session ;
@@ -17,7 +18,7 @@ trait IsResponse
1718{
1819 private(set) Status $ status = Status::OK ;
1920
20- private(set) View |string |array |Generator |null $ body = null ;
21+ private(set) View |string |array |Generator |JsonSerializable | null $ body = null ;
2122
2223 /** @var \Tempest\Http\Header[] */
2324 private(set) array $ headers = [];
Original file line number Diff line number Diff line change 55namespace Tempest \Http ;
66
77use Generator ;
8+ use JsonSerializable ;
89use Tempest \Http \Cookie \Cookie ;
910use Tempest \View \View ;
1011
@@ -19,7 +20,7 @@ interface Response
1920 get;
2021 }
2122
22- public View |string |array |Generator |null $ body {
23+ public View |string |array |Generator |JsonSerializable | null $ body {
2324 get;
2425 }
2526
Original file line number Diff line number Diff line change 55namespace Tempest \Router ;
66
77use Generator ;
8+ use JsonSerializable ;
89use Tempest \Container \Container ;
910use Tempest \Http \ContentType ;
1011use Tempest \Http \Header ;
@@ -96,7 +97,7 @@ private function sendContent(Response $response): void
9697
9798 if ($ response instanceof File || $ response instanceof Download) {
9899 readfile ($ body );
99- } elseif (is_array ($ body )) {
100+ } elseif (is_array ($ body ) || $ body instanceof JsonSerializable ) {
100101 echo json_encode ($ body );
101102 } elseif ($ body instanceof View) {
102103 echo $ this ->viewRenderer ->render ($ body );
You can’t perform that action at this time.
0 commit comments