Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public static function html($html)
* ```
*
* @param mixed $data
* @param int $status
* @return self
* @throws \InvalidArgumentException when encoding fails
*/
public static function json($data)
public static function json($data, $status = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also work:

Suggested change
public static function json($data, $status = null)
public static function json($data, $status = self::STATUS_OK)

Copy link
Author

@emrancu emrancu Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! You are right.

{
$json = @\json_encode(
$data,
Expand All @@ -159,7 +160,7 @@ public static function json($data)
);
}

return new self(self::STATUS_OK, array('Content-Type' => 'application/json'), $json . "\n");
return new self($status ? $status : self::STATUS_OK, array('Content-Type' => 'application/json'), $json . "\n");
}

/**
Expand Down