Permalink
Browse files

[HttpFoundation] JsonResponse::setEncodingOptions accepts also integer

Now you can set encoding options like:
```
$response->setEncodingOptions(JSON_UNESCAPED_UNICODE | $response->getEncodingOptions());
  • Loading branch information...
1 parent 74fb207 commit f8bc3b276fa3e24eee5e2ae041173fd9a4c81f3f @stloyd stloyd committed Jan 7, 2014
@@ -117,18 +117,13 @@ public function getEncodingOptions()
/**
* Sets options used while encoding data to JSON.
*
- * @param array $encodingOptions
+ * @param integer $encodingOptions
*
* @return JsonResponse
*/
- public function setEncodingOptions(array $encodingOptions)
+ public function setEncodingOptions($encodingOptions)
{
- $this->encodingOptions = 0;
- foreach ($encodingOptions as $encodingOption) {
- if (($this->encodingOptions & $encodingOption) != $encodingOption) {
- $this->encodingOptions |= $encodingOption;
- }
- }
+ $this->encodingOptions = (integer) $encodingOptions;
return $this->setData(json_decode($this->data));
}
@@ -180,7 +180,7 @@ public function testSetEncodingOptions()
$this->assertEquals('[[1,2,3]]', $response->getContent());
- $response->setEncodingOptions(array(JSON_FORCE_OBJECT));
+ $response->setEncodingOptions(JSON_FORCE_OBJECT);
$this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
}

0 comments on commit f8bc3b2

Please sign in to comment.