Skip to content

Commit 68a269a

Browse files
committed
Merge branch 'alieffring/8.x' into 8.x
2 parents 4236ce7 + 850c147 commit 68a269a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Illuminate/Http/JsonResponse.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ class JsonResponse extends BaseJsonResponse
2222
* @param int $status
2323
* @param array $headers
2424
* @param int $options
25+
* @param bool $json
2526
* @return void
2627
*/
27-
public function __construct($data = null, $status = 200, $headers = [], $options = 0)
28+
public function __construct($data = null, $status = 200, $headers = [], $options = 0, $json = false)
2829
{
2930
$this->encodingOptions = $options;
3031

31-
parent::__construct($data, $status, $headers);
32+
parent::__construct($data, $status, $headers, $json);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public static function fromJsonString(?string $data = null, int $status = 200, array $headers = [])
39+
{
40+
return new static($data, $status, $headers, 0, true);
3241
}
3342

3443
/**

tests/Http/HttpJsonResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ public function jsonErrorDataProvider()
104104
[$nan],
105105
];
106106
}
107+
108+
public function testFromJsonString()
109+
{
110+
$json_string = '{"foo":"bar"}';
111+
$response = JsonResponse::fromJsonString($json_string);
112+
113+
$this->assertSame('bar', $response->getData()->foo);
114+
}
107115
}
108116

109117
class JsonResponseTestJsonableObject implements Jsonable

0 commit comments

Comments
 (0)