Skip to content

[HttpFoundation] JsonResponse::setEncodingOptions accepts also integer #9963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2014
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 3 additions & 8 deletions src/Symfony/Component/HttpFoundation/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to rename this method to setEncodingFlags() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno, I was following the description from the php.net where this is called options not flags, but I can change it if you want.

{
$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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down