Skip to content

Commit

Permalink
Add named constructor on JsonResponse
Browse files Browse the repository at this point in the history
To make easier construction with raw json
  • Loading branch information
tyx committed Aug 8, 2016
1 parent 64ace10 commit 6d5a65d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Symfony/Component/HttpFoundation/JsonResponse.php
Expand Up @@ -58,6 +58,14 @@ public static function create($data = null, $status = 200, $headers = array())
return new static($data, $status, $headers);
}

/**
* Make easier the creation of JsonResponse from raw json.
*/
public static function fromJsonString($data = null, $status = 200, $headers = array())
{
return new static($data, $status, $headers, true);
}

/**
* Sets the JSONP callback.
*
Expand Down
Expand Up @@ -198,6 +198,12 @@ public function testSetEncodingOptions()
$this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
}

public function testItAcceptsJsonAsString()
{
$response = JsonResponse::fromJsonString('{"foo":"bar"}');
$this->assertSame('{"foo":"bar"}', $response->getContent());
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down

0 comments on commit 6d5a65d

Please sign in to comment.