Commit dc28083a authored by webchick's avatar webchick

Revert "Issue #1894508 by linclark, damiankloip: Update symfony/serializer."

Caused a conflict with a higher-priority patch; temporary rollback for now.

This reverts commit ba6d3fb7.
parent 783caf38
...@@ -811,18 +811,18 @@ ...@@ -811,18 +811,18 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/Serializer", "url": "https://github.com/symfony/Serializer",
"reference": "45fe843e3144a594f93a6a372385c6534c7df31c" "reference": "ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://github.com/symfony/Serializer/archive/45fe843e3144a594f93a6a372385c6534c7df31c.zip", "url": "https://github.com/symfony/Serializer/archive/ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0.zip",
"reference": "45fe843e3144a594f93a6a372385c6534c7df31c", "reference": "ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.3" "php": ">=5.3.3"
}, },
"time": "2013-01-19 07:50:02", "time": "2012-12-19 07:09:49",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
......
...@@ -32,7 +32,7 @@ class ComplexDataNormalizer extends NormalizerBase { ...@@ -32,7 +32,7 @@ class ComplexDataNormalizer extends NormalizerBase {
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize(). * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize().
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
$attributes = array(); $attributes = array();
foreach ($object as $name => $field) { foreach ($object as $name => $field) {
$attributes[$name] = $this->serializer->normalize($field, $format); $attributes[$name] = $this->serializer->normalize($field, $format);
......
...@@ -31,7 +31,7 @@ class ListNormalizer extends NormalizerBase { ...@@ -31,7 +31,7 @@ class ListNormalizer extends NormalizerBase {
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize(). * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize().
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
$attributes = array(); $attributes = array();
foreach ($object as $fieldItem) { foreach ($object as $fieldItem) {
$attributes[] = $this->serializer->normalize($fieldItem, $format); $attributes[] = $this->serializer->normalize($fieldItem, $format);
......
...@@ -25,7 +25,7 @@ class TypedDataNormalizer extends NormalizerBase { ...@@ -25,7 +25,7 @@ class TypedDataNormalizer extends NormalizerBase {
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize(). * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize().
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
return $object->getValue(); return $object->getValue();
} }
......
...@@ -44,9 +44,9 @@ public function __construct() { ...@@ -44,9 +44,9 @@ public function __construct() {
/** /**
* Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode(). * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode().
*/ */
public function encode($data, $format, array $context = array()){ public function encode($data, $format){
$normalized = $this->serializer->normalize($data, $format, $context); $normalized = $this->serializer->normalize($data, $format);
return $this->baseEncoder->encode($normalized, $format, $context); return $this->baseEncoder->encode($normalized, $format);
} }
/** /**
...@@ -59,8 +59,8 @@ public function supportsEncoding($format) { ...@@ -59,8 +59,8 @@ public function supportsEncoding($format) {
/** /**
* Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::decode(). * Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::decode().
*/ */
public function decode($data, $format, array $context = array()){ public function decode($data, $format){
return $this->baseEncoder->decode($data, $format, $context); return $this->baseEncoder->decode($data, $format);
} }
/** /**
......
...@@ -27,7 +27,7 @@ class JsonldEntityNormalizer extends JsonldNormalizerBase implements Denormalize ...@@ -27,7 +27,7 @@ class JsonldEntityNormalizer extends JsonldNormalizerBase implements Denormalize
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
*/ */
public function normalize($entity, $format = NULL, array $context = array()) { public function normalize($entity, $format = NULL) {
$entity_wrapper = new JsonldEntityWrapper($entity, $format, $this->serializer, $this->siteSchemaManager); $entity_wrapper = new JsonldEntityWrapper($entity, $format, $this->serializer, $this->siteSchemaManager);
$attributes = $entity_wrapper->getProperties(); $attributes = $entity_wrapper->getProperties();
...@@ -43,7 +43,7 @@ public function normalize($entity, $format = NULL, array $context = array()) { ...@@ -43,7 +43,7 @@ public function normalize($entity, $format = NULL, array $context = array()) {
* *
* @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException * @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/ */
public function denormalize($data, $class, $format = null, array $context = array()) { public function denormalize($data, $class, $format = null) {
if (!isset($data['@type'])) { if (!isset($data['@type'])) {
throw new UnexpectedValueException('JSON-LD @type parameter must be included.'); throw new UnexpectedValueException('JSON-LD @type parameter must be included.');
} }
......
...@@ -30,7 +30,7 @@ class JsonldEntityReferenceNormalizer extends JsonldNormalizerBase implements De ...@@ -30,7 +30,7 @@ class JsonldEntityReferenceNormalizer extends JsonldNormalizerBase implements De
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
// @todo If an $options parameter is added to the serialize signature, as // @todo If an $options parameter is added to the serialize signature, as
// requested in https://github.com/symfony/symfony/pull/4938, then instead // requested in https://github.com/symfony/symfony/pull/4938, then instead
// of creating the array of properties, we could simply call normalize and // of creating the array of properties, we could simply call normalize and
...@@ -45,7 +45,7 @@ public function normalize($object, $format = NULL, array $context = array()) { ...@@ -45,7 +45,7 @@ public function normalize($object, $format = NULL, array $context = array()) {
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize()
*/ */
public function denormalize($data, $class, $format = null, array $context = array()) { public function denormalize($data, $class, $format = null) {
// @todo Support denormalization for Entity Reference. // @todo Support denormalization for Entity Reference.
return array(); return array();
} }
......
...@@ -27,14 +27,14 @@ class JsonldFieldItemNormalizer extends JsonldNormalizerBase implements Denormal ...@@ -27,14 +27,14 @@ class JsonldFieldItemNormalizer extends JsonldNormalizerBase implements Denormal
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
return $object->getPropertyValues(); return $object->getPropertyValues();
} }
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize()
*/ */
public function denormalize($data, $class, $format = null, array $context = array()) { public function denormalize($data, $class, $format = null) {
// For most fields, the field items array should simply be returned as is. // For most fields, the field items array should simply be returned as is.
return $data; return $data;
} }
......
...@@ -25,7 +25,7 @@ class JsonldRdfSchemaNormalizer extends JsonldNormalizerBase { ...@@ -25,7 +25,7 @@ class JsonldRdfSchemaNormalizer extends JsonldNormalizerBase {
/** /**
* Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
*/ */
public function normalize($data, $format = NULL, array $context = array()) { public function normalize($data, $format = NULL) {
$normalized = array(); $normalized = array();
$graph = $data->getGraph(); $graph = $data->getGraph();
......
...@@ -29,7 +29,7 @@ class SerializationTestEncoder implements EncoderInterface { ...@@ -29,7 +29,7 @@ class SerializationTestEncoder implements EncoderInterface {
* @return string * @return string
* A string representation of $data in the requested format. * A string representation of $data in the requested format.
*/ */
public function encode($data, $format, array $context = array()) { public function encode($data, $format) {
// @see Drupal\serialization_test\SerializationTestNormalizer::normalize(). // @see Drupal\serialization_test\SerializationTestNormalizer::normalize().
return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder'; return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder';
} }
......
...@@ -30,7 +30,7 @@ class SerializationTestNormalizer implements NormalizerInterface { ...@@ -30,7 +30,7 @@ class SerializationTestNormalizer implements NormalizerInterface {
* An array containing a normalized representation of $object, appropriate * An array containing a normalized representation of $object, appropriate
* for encoding to the requested format. * for encoding to the requested format.
*/ */
public function normalize($object, $format = NULL, array $context = array()) { public function normalize($object, $format = NULL) {
$normalized = (array) $object; $normalized = (array) $object;
// Add identifying value that can be used to verify that the expected // Add identifying value that can be used to verify that the expected
// normalizer was invoked. // normalizer was invoked.
......
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit3c7622c3b1ba2ec69ca397628a542de0::getLoader(); return ComposerAutoloaderInitdff5596d4902476e49b77f22ebf69e4a::getLoader();
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// autoload_real.php generated by Composer // autoload_real.php generated by Composer
class ComposerAutoloaderInit3c7622c3b1ba2ec69ca397628a542de0 class ComposerAutoloaderInitdff5596d4902476e49b77f22ebf69e4a
{ {
private static $loader; private static $loader;
...@@ -19,9 +19,9 @@ public static function getLoader() ...@@ -19,9 +19,9 @@ public static function getLoader()
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit3c7622c3b1ba2ec69ca397628a542de0', 'loadClassLoader')); spl_autoload_register(array('ComposerAutoloaderInitdff5596d4902476e49b77f22ebf69e4a', 'loadClassLoader'));
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit3c7622c3b1ba2ec69ca397628a542de0', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitdff5596d4902476e49b77f22ebf69e4a', 'loadClassLoader'));
$vendorDir = dirname(__DIR__); $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
......
...@@ -575,6 +575,55 @@ ...@@ -575,6 +575,55 @@
"description": "Symfony Routing Component", "description": "Symfony Routing Component",
"homepage": "http://symfony.com" "homepage": "http://symfony.com"
}, },
{
"name": "symfony/serializer",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer",
"reference": "ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Serializer/archive/ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0.zip",
"reference": "ef3d92815bdb07281ee8cbd73b3e3f9e41bdc1a0",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2012-12-19 07:09:49",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
}
},
"installation-source": "source",
"autoload": {
"psr-0": {
"Symfony\\Component\\Serializer\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com"
},
{ {
"name": "symfony/yaml", "name": "symfony/yaml",
"version": "dev-master", "version": "dev-master",
...@@ -931,54 +980,5 @@ ...@@ -931,54 +980,5 @@
"database", "database",
"routing" "routing"
] ]
},
{
"name": "symfony/serializer",
"version": "dev-master",
"version_normalized": "9999999-dev",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer",
"reference": "45fe843e3144a594f93a6a372385c6534c7df31c"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Serializer/archive/45fe843e3144a594f93a6a372385c6534c7df31c.zip",
"reference": "45fe843e3144a594f93a6a372385c6534c7df31c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2013-01-19 07:50:02",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
}
},
"installation-source": "source",
"autoload": {
"psr-0": {
"Symfony\\Component\\Serializer\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com"
} }
] ]
/Tests export-ignore
phpunit.xml.dist export-ignore
CHANGELOG CHANGELOG
========= =========
2.2.0
-----
* [BC BREAK] All Serializer, Normalizer and Encoder interfaces have been
modified to include an optional `$context` array parameter.
* The XML Root name can now be configured with the `xml_root_name`
parameter in the context option to the `XmlEncoder`.
* Options to `json_encode` and `json_decode` can be passed through
the context options of `JsonEncode` and `JsonDecode` encoder/decoders.
2.1.0 2.1.0
----- -----
......
...@@ -34,9 +34,9 @@ public function __construct(array $decoders = array()) ...@@ -34,9 +34,9 @@ public function __construct(array $decoders = array())
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
final public function decode($data, $format, array $context = array()) final public function decode($data, $format)
{ {
return $this->getDecoder($format)->decode($data, $format, $context); return $this->getDecoder($format)->decode($data, $format);
} }
/** /**
......
...@@ -35,9 +35,9 @@ public function __construct(array $encoders = array()) ...@@ -35,9 +35,9 @@ public function __construct(array $encoders = array())
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
final public function encode($data, $format, array $context = array()) final public function encode($data, $format)
{ {
return $this->getEncoder($format)->encode($data, $format, $context); return $this->getEncoder($format)->encode($data, $format);
} }
/** /**
......
...@@ -23,11 +23,10 @@ interface DecoderInterface ...@@ -23,11 +23,10 @@ interface DecoderInterface
* *
* @param scalar $data Data to decode * @param scalar $data Data to decode
* @param string $format Format name * @param string $format Format name
* @param array $context options that decoders have access to.
* *
* @return mixed * @return mixed
*/ */
public function decode($data, $format, array $context = array()); public function decode($data, $format);
/** /**
* Checks whether the serializer can decode from given format * Checks whether the serializer can decode from given format
......
...@@ -23,11 +23,10 @@ interface EncoderInterface ...@@ -23,11 +23,10 @@ interface EncoderInterface
* *
* @param mixed $data Data to encode * @param mixed $data Data to encode
* @param string $format Format name * @param string $format Format name
* @param array $context options that normalizers/encoders have access to.
* *
* @return scalar * @return scalar
*/ */
public function encode($data, $format, array $context = array()); public function encode($data, $format);
/** /**
* Checks whether the serializer can encode to given format * Checks whether the serializer can encode to given format
......
...@@ -21,7 +21,6 @@ class JsonDecode implements DecoderInterface ...@@ -21,7 +21,6 @@ class JsonDecode implements DecoderInterface
private $associative; private $associative;
private $recursionDepth; private $recursionDepth;
private $lastError = JSON_ERROR_NONE; private $lastError = JSON_ERROR_NONE;
protected $serializer;
public function __construct($associative = false, $depth = 512) public function __construct($associative = false, $depth = 512)
{ {
...@@ -49,20 +48,9 @@ public function getLastError() ...@@ -49,20 +48,9 @@ public function getLastError()
* *
* @return mixed * @return mixed
*/ */
public function decode($data, $format, array $context = array()) public function decode($data, $format)
{ {
$context = $this->resolveContext($context); $decodedData = json_decode($data, $this->associative, $this->recursionDepth);
$associative = $context['json_decode_associative'];
$recursionDepth = $context['json_decode_recursion_depth'];
$options = $context['json_decode_options'];
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
} else {
$decodedData = json_decode($data, $associative, $recursionDepth);
}
$this->lastError = json_last_error(); $this->lastError = json_last_error();
return $decodedData; return $decodedData;
...@@ -75,21 +63,4 @@ public function supportsDecoding($format) ...@@ -75,21 +63,4 @@ public function supportsDecoding($format)
{ {
return JsonEncoder::FORMAT === $format; return JsonEncoder::FORMAT === $format;
} }
/**
* Merge the default options of the Json Decoder with the passed context.
*
* @param array $context
* @return array
*/
private function resolveContext(array $context)
{
$defaultOptions = array(
'json_decode_associative' => $this->associative,
'json_decode_recursion_depth' => $this->recursionDepth,
'json_decode_options' => 0
);
return array_merge($defaultOptions, $context);
}
} }
...@@ -41,13 +41,14 @@ public function getLastError() ...@@ -41,13 +41,14 @@ public function getLastError()
/** /**
* Encodes PHP data to a JSON string * Encodes PHP data to a JSON string
* *
* {@inheritdoc} * @param mixed $data
* @param string $format
*
* @return string
*/ */
public function encode($data, $format, array $context = array()) public function encode($data, $format)
{ {
$context = $this->resolveContext($context); $encodedJson = json_encode($data, $this->options);
$encodedJson = json_encode($data, $context['json_encode_options']);
$this->lastError = json_last_error(); $this->lastError = json_last_error();
return $encodedJson; return $encodedJson;
...@@ -60,15 +61,4 @@ public function supportsEncoding($format) ...@@ -60,15 +61,4 @@ public function supportsEncoding($format)
{ {
return JsonEncoder::FORMAT === $format; return JsonEncoder::FORMAT === $format;
} }
/**
* Merge default json encode options with context.
*
* @param array $context
* @return array
*/
private function resolveContext(array $context = array())
{
return array_merge(array('json_encode_options' => $this->options), $context);
}
} }
...@@ -59,17 +59,17 @@ public function getLastDecodingError() ...@@ -59,17 +59,17 @@ public function getLastDecodingError()
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function encode($data, $format, array $context = array()) public function encode($data, $format)
{ {
return $this->encodingImpl->encode($data, self::FORMAT, $context); return $this->encodingImpl->encode($data, self::FORMAT);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function decode($data, $format, array $context = array()) public function decode($data, $format)
{ {
return $this->decodingImpl->decode($data, self::FORMAT, $context); return $this->decodingImpl->decode($data, self::FORMAT);
} }