8000 [Serializer] Add options to JsonDecode and JsonEncode to wrap/unwrap json data by nonanerz · Pull Request #28887 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Add options to JsonDecode and JsonEncode to wrap/unwrap json data #28887

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
resolve conflict
  • Loading branch information
nonanerz committed Mar 4, 2019
commit 08267704d66aefef32603de1168b7594cf630d30
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(ContainerInterface $container)
*
* @param string $eventName The name of the event to dispatch. The name of the event is
* the name of the method that is invoked on listeners.
* @param EventArgs $eventArgs The event arguments to pass to the event handlers/listeners.
* If not supplied, the single empty EventArgs instance is used.
* @param EventArgs $eventArgs the event arguments to pass to the event handlers/listeners.
* If not supplied, the single empty EventArgs instance is used
*
* @return bool
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Component/Serializer/Encoder/JsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class JsonEncode implements EncoderInterface
{
const OPTIONS = 'json_encode_options';

private $defaultContext = [
private $propertyAccessor;
private $defaultContext = []
private $defaultContext = [
self::OPTIONS => 0,
JsonEncoder::JSON_PROPERTY_PATH => null,
];
Expand Down Expand Up @@ -78,7 +77,7 @@ public function encode($data, $format, array $context = [])
*/
private function wrapEncodableData($propertyPath, $data)
{
$wrappedData = array();
$wrappedData = [];
$this->propertyAccessor->setValue($wrappedData, $propertyPath, $data);

return $wrappedData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function decodeProvider()

$assoc = ['foo' => 'bar'];

return array(
return [
['{"foo": "bar"}', $stdClass, []],
['{"foo": "bar"}', $assoc, ['json_decode_associative' => true]],
array('{"baz": {"foo": "bar"}}', $stdClass, array(JsonEncoder::JSON_PROPERTY_PATH => 'baz')),
array('{"baz": {"foo": "bar"}}', null, array(JsonEncoder::JSON_PROPERTY_PATH => 'baz.inner')),
array('{"baz": {"foo": "bar"}}', $assoc, array(JsonEncoder::JSON_PROPERTY_PATH => '[baz]', 'json_decode_associative' => true)),
array('{"baz": {"foo": "bar"}}', $assoc, array(JsonEncoder::JSON_PROPERTY_PATH => '[baz]', 'json_decode_associative' => true)),
array('{"baz": {"foo": "bar", "inner": {"key": "value"}}}', array('key' => 'value'), array(JsonEncoder::JSON_PROPERTY_PATH => '[baz][inner]', 'json_decode_associative' => true)),
);
['{"baz": {"foo": "bar"}}', $stdClass, [JsonEncoder::JSON_PROPERTY_PATH => 'baz']],
['{"baz": {"foo": "bar"}}', null, [JsonEncoder::JSON_PROPERTY_PATH => 'baz.inner']],
['{"baz": {"foo": "bar"}}', $assoc, [JsonEncoder::JSON_PROPERTY_PATH => '[baz]', 'json_decode_associative' => true]],
['{"baz": {"foo": "bar"}}', $assoc, [JsonEncoder::JSON_PROPERTY_PATH => '[baz]', 'json_decode_associative' => true]],
['{"baz": {"foo": "bar", "inner": {"key": "value"}}}', ['key' => 'value'], [JsonEncoder::JSON_PROPERTY_PATH => '[baz][inner]', 'json_decode_associative' => true]],
];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function testEncode($toEncode, $expected, $context)

public function encodeProvider()
{
return array(
array(array(), '[]', array()),
array(array(), '{}', array('json_encode_options' => JSON_FORCE_OBJECT)),
array(array('bar' => 'foo'), '{"baz":{"bar":"foo"}}', array(JsonEncoder::JSON_PROPERTY_PATH => '[baz]')),
);
return [
[[], '[]', []],
[[], '{}', ['json_encode_options' => JSON_FORCE_OBJECT]],
[['bar' => 'foo'], '{"baz":{"bar":"foo"}}', [JsonEncoder::JSON_PROPERTY_PATH => '[baz]']],
];
}

/**
Expand Down
0