X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fserializer%2FSerializer.php;h=72c5721c89928e7b304f2c51dda34558238912c3;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hp=c3e35bb0267cc2288de4c941c09440a649bc8fed;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/vendor/symfony/serializer/Serializer.php b/vendor/symfony/serializer/Serializer.php index c3e35bb02..72c5721c8 100644 --- a/vendor/symfony/serializer/Serializer.php +++ b/vendor/symfony/serializer/Serializer.php @@ -13,14 +13,15 @@ namespace Symfony\Component\Serializer; use Symfony\Component\Serializer\Encoder\ChainDecoder; use Symfony\Component\Serializer\Encoder\ChainEncoder; -use Symfony\Component\Serializer\Encoder\EncoderInterface; use Symfony\Component\Serializer\Encoder\DecoderInterface; +use Symfony\Component\Serializer\Encoder\EncoderInterface; +use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Exception\NotEncodableValueException; +use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -use Symfony\Component\Serializer\Exception\LogicException; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** * Serializer serializes and deserializes data. @@ -28,9 +29,9 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException; * objects are turned into arrays by normalizers. * arrays are turned into various output formats by encoders. * - * $serializer->serialize($obj, 'xml') - * $serializer->decode($data, 'xml') - * $serializer->denormalize($data, 'Class', 'xml') + * $serializer->serialize($obj, 'xml') + * $serializer->decode($data, 'xml') + * $serializer->denormalize($data, 'Class', 'xml') * * @author Jordi Boggiano * @author Johannes M. Schmitt @@ -107,11 +108,11 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz */ final public function serialize($data, $format, array $context = array()) { - if (!$this->supportsEncoding($format)) { - throw new UnexpectedValueException(sprintf('Serialization for the format %s is not supported', $format)); + if (!$this->supportsEncoding($format, $context)) { + throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format)); } - if ($this->encoder->needsNormalization($format)) { + if ($this->encoder->needsNormalization($format, $context)) { $data = $this->normalize($data, $format, $context); } @@ -123,8 +124,8 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz */ final public function deserialize($data, $type, $format, array $context = array()) { - if (!$this->supportsDecoding($format)) { - throw new UnexpectedValueException(sprintf('Deserialization for the format %s is not supported', $format)); + if (!$this->supportsDecoding($format, $context)) { + throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format)); } $data = $this->decode($data, $format, $context); @@ -138,7 +139,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz public function normalize($data, $format = null, array $context = array()) { // If a normalizer supports the given data, use it - if ($normalizer = $this->getNormalizer($data, $format)) { + if ($normalizer = $this->getNormalizer($data, $format, $context)) { return $normalizer->normalize($data, $format, $context); } @@ -146,7 +147,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz return $data; } - if (is_array($data) || $data instanceof \Traversable) { + if (\is_array($data) || $data instanceof \Traversable) { $normalized = array(); foreach ($data as $key => $val) { $normalized[$key] = $this->normalize($val, $format, $context); @@ -155,53 +156,90 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz return $normalized; } - if (is_object($data)) { + if (\is_object($data)) { if (!$this->normalizers) { throw new LogicException('You must register at least one normalizer to be able to normalize objects.'); } - throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($data))); + throw new NotNormalizableValueException(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))); + throw new NotNormalizableValueException(sprintf('An unexpected value could not be normalized: %s', var_export($data, true))); } /** * {@inheritdoc} + * + * @throws NotNormalizableValueException */ public function denormalize($data, $type, $format = null, array $context = array()) { - return $this->denormalizeObject($data, $type, $format, $context); + if (!$this->normalizers) { + throw new LogicException('You must register at least one normalizer to be able to denormalize objects.'); + } + + if ($normalizer = $this->getDenormalizer($data, $type, $format, $context)) { + return $normalizer->denormalize($data, $type, $format, $context); + } + + throw new NotNormalizableValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $type)); } /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, $format = null/*, array $context = array()*/) { - return null !== $this->getNormalizer($data, $format); + if (\func_num_args() > 2) { + $context = \func_get_arg(2); + } else { + if (__CLASS__ !== \get_class($this)) { + $r = new \ReflectionMethod($this, __FUNCTION__); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error(sprintf('The "%s()" method will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED); + } + } + + $context = array(); + } + + return null !== $this->getNormalizer($data, $format, $context); } /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/) { - return null !== $this->getDenormalizer($data, $type, $format); + if (\func_num_args() > 3) { + $context = \func_get_arg(3); + } else { + if (__CLASS__ !== \get_class($this)) { + $r = new \ReflectionMethod($this, __FUNCTION__); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error(sprintf('The "%s()" method will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED); + } + } + + $context = array(); + } + + return null !== $this->getDenormalizer($data, $type, $format, $context); } /** * Returns a matching normalizer. * - * @param mixed $data Data to get the serializer for - * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param mixed $data Data to get the serializer for + * @param string $format Format name, present to give the option to normalizers to act differently based on formats + * @param array $context Options available to the normalizer * * @return NormalizerInterface|null */ - private function getNormalizer($data, $format) + private function getNormalizer($data, $format, array $context) { foreach ($this->normalizers as $normalizer) { - if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) { + if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format, $context)) { return $normalizer; } } @@ -210,16 +248,17 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz /** * Returns a matching denormalizer. * - * @param mixed $data data to restore - * @param string $class the expected class to instantiate - * @param string $format format name, present to give the option to normalizers to act differently based on formats + * @param mixed $data Data to restore + * @param string $class The expected class to instantiate + * @param string $format Format name, present to give the option to normalizers to act differently based on formats + * @param array $context Options available to the denormalizer * * @return DenormalizerInterface|null */ - private function getDenormalizer($data, $class, $format) + private function getDenormalizer($data, $class, $format, array $context) { foreach ($this->normalizers as $normalizer) { - if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format)) { + if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format, $context)) { return $normalizer; } } @@ -242,44 +281,44 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz } /** - * Denormalizes data back into an object of the given class. - * - * @param mixed $data data to restore - * @param string $class the expected class to instantiate - * @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 denormalization - * - * @return object - * - * @throws LogicException - * @throws UnexpectedValueException + * {@inheritdoc} */ - private function denormalizeObject($data, $class, $format, array $context = array()) + public function supportsEncoding($format/*, array $context = array()*/) { - if (!$this->normalizers) { - throw new LogicException('You must register at least one normalizer to be able to denormalize objects.'); - } + if (\func_num_args() > 1) { + $context = \func_get_arg(1); + } else { + if (__CLASS__ !== \get_class($this)) { + $r = new \ReflectionMethod($this, __FUNCTION__); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error(sprintf('The "%s()" method will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED); + } + } - if ($normalizer = $this->getDenormalizer($data, $class, $format)) { - return $normalizer->denormalize($data, $class, $format, $context); + $context = array(); } - throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class)); + return $this->encoder->supportsEncoding($format, $context); } /** * {@inheritdoc} */ - public function supportsEncoding($format) + public function supportsDecoding($format/*, array $context = array()*/) { - return $this->encoder->supportsEncoding($format); - } + if (\func_num_args() > 1) { + $context = \func_get_arg(1); + } else { + if (__CLASS__ !== \get_class($this)) { + $r = new \ReflectionMethod($this, __FUNCTION__); + if (__CLASS__ !== $r->getDeclaringClass()->getName()) { + @trigger_error(sprintf('The "%s()" method will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since Symfony 3.3.', __METHOD__), E_USER_DEPRECATED); + } + } - /** - * {@inheritdoc} - */ - public function supportsDecoding($format) - { - return $this->decoder->supportsDecoding($format); + $context = array(); + } + + return $this->decoder->supportsDecoding($format, $context); } }