diff --git a/docs/response.md b/docs/response.md index c47229b..99b022f 100644 --- a/docs/response.md +++ b/docs/response.md @@ -97,7 +97,7 @@ This method returns the message body in JSON format. - `$headers` (array): The headers of the response. ```php -$response->json('{"message":"Hello World!"}', $status, $headers); +Response::json('{"message":"Hello World!"}', $status, $headers); ``` ## Method `Response::plain(string $content, Status|array $status = Status::Ok, array $headers = [])`. @@ -109,7 +109,7 @@ This method returns the message body in plain text format. - `$headers` (array): The headers of the response ```php -$response->plain('Hello World!', $status, $headers); +Response::plain('Hello World!', $status, $headers); ``` ## Method `Response::html(string $content, Status|array $status = Status::Ok, array $headers = [])`. @@ -121,7 +121,7 @@ This method returns the message body in HTML format. - `$headers` (array): The headers of the response ```php -$response->html('

Hello World!

', $status, $headers); +Response::html('

Hello World!

', $status, $headers); ``` ## Method `Response::xml(string $content, Status|array $status = Status::Ok, array $headers = [])`. @@ -142,5 +142,5 @@ $xml=<<Don't forget me this weekend! XML; -$response->xml($xml, $status, $headers); +Response::xml($xml, $status, $headers); ``` \ No newline at end of file diff --git a/src/Response.php b/src/Response.php index 8c853a4..3ad3c8d 100644 --- a/src/Response.php +++ b/src/Response.php @@ -165,10 +165,13 @@ protected function send(): string /** * Devuelve cuerpo del mensaje como JSON */ - public static function json(array|object $content, Status|array $status = Status::Ok, array $headers = []): Response + public static function json(array|string $content, Status|array $status = Status::Ok, array $headers = []): Response { $headers['content-type'] = 'application/json'; - return new static(json_encode($content, JSON_PRETTY_PRINT), $status, $headers); + return new static( + is_string($content) ? $content : json_encode($content,JSON_PRETTY_PRINT), + $status, + $headers); } /**