Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
72
vendor/symfony/serializer/Serializer.php
vendored
72
vendor/symfony/serializer/Serializer.php
vendored
|
@ -41,18 +41,22 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
* @var Encoder\ChainEncoder
|
||||
*/
|
||||
protected $encoder;
|
||||
|
||||
/**
|
||||
* @var Encoder\ChainDecoder
|
||||
*/
|
||||
protected $decoder;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $normalizers = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $normalizerCache = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -127,10 +131,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
if (null === $data || is_scalar($data)) {
|
||||
return $data;
|
||||
}
|
||||
if (is_object($data) && $this->supportsNormalization($data, $format)) {
|
||||
return $this->normalizeObject($data, $format, $context);
|
||||
}
|
||||
if ($data instanceof \Traversable) {
|
||||
|
||||
if (is_array($data) || $data instanceof \Traversable) {
|
||||
$normalized = array();
|
||||
foreach ($data as $key => $val) {
|
||||
$normalized[$key] = $this->normalize($val, $format, $context);
|
||||
|
@ -138,16 +140,15 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
if (is_object($data)) {
|
||||
return $this->normalizeObject($data, $format, $context);
|
||||
}
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $val) {
|
||||
$data[$key] = $this->normalize($val, $format, $context);
|
||||
if (!$this->normalizers) {
|
||||
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
|
||||
}
|
||||
|
||||
return $data;
|
||||
throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($data)));
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true)));
|
||||
}
|
||||
|
||||
|
@ -185,19 +186,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
*/
|
||||
private function getNormalizer($data, $format)
|
||||
{
|
||||
if ($isObject = is_object($data)) {
|
||||
$class = get_class($data);
|
||||
if (isset($this->normalizerCache[$class][$format])) {
|
||||
return $this->normalizerCache[$class][$format];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->normalizers as $normalizer) {
|
||||
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) {
|
||||
if ($isObject) {
|
||||
$this->normalizerCache[$class][$format] = $normalizer;
|
||||
}
|
||||
|
||||
return $normalizer;
|
||||
}
|
||||
}
|
||||
|
@ -214,14 +204,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
*/
|
||||
private function getDenormalizer($data, $class, $format)
|
||||
{
|
||||
if (isset($this->denormalizerCache[$class][$format])) {
|
||||
return $this->denormalizerCache[$class][$format];
|
||||
}
|
||||
|
||||
foreach ($this->normalizers as $normalizer) {
|
||||
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format)) {
|
||||
$this->denormalizerCache[$class][$format] = $normalizer;
|
||||
|
||||
return $normalizer;
|
||||
}
|
||||
}
|
||||
|
@ -243,30 +227,6 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
return $this->decoder->decode($data, $format, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes an object into a set of arrays/scalars.
|
||||
*
|
||||
* @param object $object object to normalize
|
||||
* @param string $format format name, present to give the option to normalizers to act differently based on formats
|
||||
* @param array $context The context data for this particular normalization
|
||||
*
|
||||
* @return array|string|bool|int|float|null
|
||||
*
|
||||
* @throws LogicException
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
private function normalizeObject($object, $format, array $context = array())
|
||||
{
|
||||
if (!$this->normalizers) {
|
||||
throw new LogicException('You must register at least one normalizer to be able to normalize objects.');
|
||||
}
|
||||
|
||||
if ($normalizer = $this->getNormalizer($object, $format)) {
|
||||
return $normalizer->normalize($object, $format, $context);
|
||||
}
|
||||
throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($object)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Denormalizes data back into an object of the given class.
|
||||
*
|
||||
|
@ -289,6 +249,16 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz
|
|||
if ($normalizer = $this->getDenormalizer($data, $class, $format)) {
|
||||
return $normalizer->denormalize($data, $class, $format, $context);
|
||||
}
|
||||
|
||||
foreach ($this->normalizers as $normalizer) {
|
||||
if (
|
||||
$normalizer instanceof DenormalizerInterface &&
|
||||
$normalizer->supportsDenormalization($data, $class, $format)
|
||||
) {
|
||||
return $normalizer->denormalize($data, $class, $format, $context);
|
||||
}
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue