[Serializer] Add more parameter types.
This commit is contained in:
parent
86a2a9df23
commit
73b17a8ecf
@ -102,7 +102,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsEncoding($format)
|
public function supportsEncoding(string $format)
|
||||||
{
|
{
|
||||||
return self::FORMAT === $format;
|
return self::FORMAT === $format;
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDecoding($format)
|
public function supportsDecoding(string $format)
|
||||||
{
|
{
|
||||||
return self::FORMAT === $format;
|
return self::FORMAT === $format;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ final class ObjectPropertyListExtractor implements ObjectPropertyListExtractorIn
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getProperties($object, array $context = []): ?array
|
public function getProperties(object $object, array $context = []): ?array
|
||||||
{
|
{
|
||||||
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
|
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
|
||||||
|
|
||||||
|
@ -19,9 +19,7 @@ interface ObjectPropertyListExtractorInterface
|
|||||||
/**
|
/**
|
||||||
* Gets the list of properties available for the given object.
|
* Gets the list of properties available for the given object.
|
||||||
*
|
*
|
||||||
* @param object $object
|
|
||||||
*
|
|
||||||
* @return string[]|null
|
* @return string[]|null
|
||||||
*/
|
*/
|
||||||
public function getProperties($object, array $context = []): ?array;
|
public function getProperties(object $object, array $context = []): ?array;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ class AttributeMetadata implements AttributeMetadataInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function addGroup($group)
|
public function addGroup(string $group)
|
||||||
{
|
{
|
||||||
if (!\in_array($group, $this->groups)) {
|
if (!\in_array($group, $this->groups)) {
|
||||||
$this->groups[] = $group;
|
$this->groups[] = $group;
|
||||||
@ -84,7 +84,7 @@ class AttributeMetadata implements AttributeMetadataInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function setMaxDepth($maxDepth)
|
public function setMaxDepth(?int $maxDepth)
|
||||||
{
|
{
|
||||||
$this->maxDepth = $maxDepth;
|
$this->maxDepth = $maxDepth;
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@ interface AdvancedNameConverterInterface extends NameConverterInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($propertyName, string $class = null, string $format = null, array $context = []);
|
public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($propertyName, string $class = null, string $format = null, array $context = []);
|
public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($propertyName, string $class = null, string $format = null, array $context = []): string
|
public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
|
||||||
{
|
{
|
||||||
if (null === $class) {
|
if (null === $class) {
|
||||||
return $this->normalizeFallback($propertyName, $class, $format, $context);
|
return $this->normalizeFallback($propertyName, $class, $format, $context);
|
||||||
@ -56,7 +56,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($propertyName, string $class = null, string $format = null, array $context = []): string
|
public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
|
||||||
{
|
{
|
||||||
if (null === $class) {
|
if (null === $class) {
|
||||||
return $this->denormalizeFallback($propertyName, $class, $format, $context);
|
return $this->denormalizeFallback($propertyName, $class, $format, $context);
|
||||||
|
@ -170,14 +170,11 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
/**
|
/**
|
||||||
* Detects if the configured circular reference limit is reached.
|
* Detects if the configured circular reference limit is reached.
|
||||||
*
|
*
|
||||||
* @param object $object
|
|
||||||
* @param array $context
|
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @throws CircularReferenceException
|
* @throws CircularReferenceException
|
||||||
*/
|
*/
|
||||||
protected function isCircularReference($object, &$context)
|
protected function isCircularReference(object $object, array &$context)
|
||||||
{
|
{
|
||||||
$objectHash = spl_object_hash($object);
|
$objectHash = spl_object_hash($object);
|
||||||
|
|
||||||
@ -229,7 +226,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
*
|
*
|
||||||
* @return string[]|AttributeMetadataInterface[]|bool
|
* @return string[]|AttributeMetadataInterface[]|bool
|
||||||
*/
|
*/
|
||||||
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false)
|
||||||
{
|
{
|
||||||
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
|
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
|
||||||
if (!$this->classMetadataFactory) {
|
if (!$this->classMetadataFactory) {
|
||||||
@ -265,12 +262,10 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
* Is this attribute allowed?
|
* Is this attribute allowed?
|
||||||
*
|
*
|
||||||
* @param object|string $classOrObject
|
* @param object|string $classOrObject
|
||||||
* @param string $attribute
|
|
||||||
* @param string|null $format
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
|
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
|
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
|
||||||
if (\in_array($attribute, $ignoredAttributes)) {
|
if (\in_array($attribute, $ignoredAttributes)) {
|
||||||
@ -307,12 +302,11 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
* Returns the method to use to construct an object. This method must be either
|
* Returns the method to use to construct an object. This method must be either
|
||||||
* the object constructor or static.
|
* the object constructor or static.
|
||||||
*
|
*
|
||||||
* @param string $class
|
|
||||||
* @param array|bool $allowedAttributes
|
* @param array|bool $allowedAttributes
|
||||||
*
|
*
|
||||||
* @return \ReflectionMethod|null
|
* @return \ReflectionMethod|null
|
||||||
*/
|
*/
|
||||||
protected function getConstructor(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
|
protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
|
||||||
{
|
{
|
||||||
return $reflectionClass->getConstructor();
|
return $reflectionClass->getConstructor();
|
||||||
}
|
}
|
||||||
@ -325,7 +319,6 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
* is removed from the context before being returned to avoid side effects
|
* is removed from the context before being returned to avoid side effects
|
||||||
* when recursively normalizing an object graph.
|
* when recursively normalizing an object graph.
|
||||||
*
|
*
|
||||||
* @param string $class
|
|
||||||
* @param array|bool $allowedAttributes
|
* @param array|bool $allowedAttributes
|
||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
@ -333,7 +326,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @throws MissingConstructorArgumentsException
|
* @throws MissingConstructorArgumentsException
|
||||||
*/
|
*/
|
||||||
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
||||||
{
|
{
|
||||||
if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) {
|
if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) {
|
||||||
unset($context[self::OBJECT_TO_POPULATE]);
|
unset($context[self::OBJECT_TO_POPULATE]);
|
||||||
@ -408,7 +401,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
|
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (null !== $parameter->getClass()) {
|
if (null !== $parameter->getClass()) {
|
||||||
|
@ -211,7 +211,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
||||||
{
|
{
|
||||||
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) {
|
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) {
|
||||||
if (!isset($data[$mapping->getTypeProperty()])) {
|
if (!isset($data[$mapping->getTypeProperty()])) {
|
||||||
@ -272,25 +272,21 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* Extracts attributes to normalize from the class of the given object, format and context.
|
* Extracts attributes to normalize from the class of the given object, format and context.
|
||||||
*
|
*
|
||||||
* @param object $object
|
|
||||||
*
|
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
abstract protected function extractAttributes($object, string $format = null, array $context = []);
|
abstract protected function extractAttributes(object $object, string $format = null, array $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the attribute value.
|
* Gets the attribute value.
|
||||||
*
|
*
|
||||||
* @param object $object
|
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract protected function getAttributeValue($object, string $attribute, string $format = null, array $context = []);
|
abstract protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
|
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
|
||||||
}
|
}
|
||||||
@ -298,7 +294,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (!isset($context['cache_key'])) {
|
if (!isset($context['cache_key'])) {
|
||||||
$context['cache_key'] = $this->getCacheKey($format, $context);
|
$context['cache_key'] = $this->getCacheKey($format, $context);
|
||||||
@ -349,13 +345,8 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets attribute value.
|
* Sets attribute value.
|
||||||
*
|
|
||||||
* @param object $object
|
|
||||||
* @param string $attribute
|
|
||||||
* @param mixed $value
|
|
||||||
* @param string|null $format
|
|
||||||
*/
|
*/
|
||||||
abstract protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = []);
|
abstract protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the submitted data and denormalizes it.
|
* Validates the submitted data and denormalizes it.
|
||||||
@ -435,7 +426,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, $parameterName, $parameterData, array $context, $format = null)
|
protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, $parameterData, array $context, string $format = null)
|
||||||
{
|
{
|
||||||
if (null === $this->propertyTypeExtractor || null === $types = $this->propertyTypeExtractor->getTypes($class->getName(), $parameterName)) {
|
if (null === $this->propertyTypeExtractor || null === $types = $this->propertyTypeExtractor->getTypes($class->getName(), $parameterName)) {
|
||||||
return parent::denormalizeParameter($class, $parameter, $parameterName, $parameterData, $context, $format);
|
return parent::denormalizeParameter($class, $parameter, $parameterName, $parameterData, $context, $format);
|
||||||
|
@ -36,7 +36,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Serializer
|
|||||||
*
|
*
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (null === $this->serializer) {
|
if (null === $this->serializer) {
|
||||||
throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
|
throw new BadMethodCallException('Please set a serializer before calling denormalize()!');
|
||||||
@ -66,7 +66,7 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Serializer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null, array $context = [])
|
public function supportsDenormalization($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return '[]' === substr($type, -2)
|
return '[]' === substr($type, -2)
|
||||||
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
|
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
|
||||||
|
@ -41,7 +41,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($object, $format = null, array $context = [])
|
public function normalize($object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$violations = [];
|
$violations = [];
|
||||||
$messages = [];
|
$messages = [];
|
||||||
@ -83,7 +83,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, string $format = null)
|
||||||
{
|
{
|
||||||
return $data instanceof ConstraintViolationListInterface;
|
return $data instanceof ConstraintViolationListInterface;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$object = $this->extractObjectToPopulate($type, $context) ?: new $type();
|
$object = $this->extractObjectToPopulate($type, $context) ?: new $type();
|
||||||
$object->denormalize($this->serializer, $data, $format, $context);
|
$object->denormalize($this->serializer, $data, $format, $context);
|
||||||
@ -63,7 +63,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return is_subclass_of($type, DenormalizableInterface::class);
|
return is_subclass_of($type, DenormalizableInterface::class);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) {
|
if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) {
|
||||||
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
|
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
|
||||||
@ -118,7 +118,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return isset(self::$supportedTypes[$type]);
|
return isset(self::$supportedTypes[$type]);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws UnexpectedValueException
|
* @throws UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (!\is_string($data)) {
|
if (!\is_string($data)) {
|
||||||
throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data)));
|
throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data)));
|
||||||
@ -118,7 +118,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return \DateInterval::class === $type;
|
return \DateInterval::class === $type;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||||||
*
|
*
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$dateTimeFormat = $context[self::FORMAT_KEY] ?? null;
|
$dateTimeFormat = $context[self::FORMAT_KEY] ?? null;
|
||||||
$timezone = $this->getTimezone($context);
|
$timezone = $this->getTimezone($context);
|
||||||
@ -113,7 +113,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return isset(self::$supportedTypes[$type]);
|
return isset(self::$supportedTypes[$type]);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||||||
*
|
*
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if ('' === $data || null === $data) {
|
if ('' === $data || null === $data) {
|
||||||
throw new NotNormalizableValueException('The data is either an empty string or null, you should pass a string that can be parsed as a DateTimeZone.');
|
throw new NotNormalizableValueException('The data is either an empty string or null, you should pass a string that can be parsed as a DateTimeZone.');
|
||||||
@ -64,7 +64,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return \DateTimeZone::class === $type;
|
return \DateTimeZone::class === $type;
|
||||||
}
|
}
|
||||||
|
@ -36,5 +36,5 @@ interface DenormalizableInterface
|
|||||||
*
|
*
|
||||||
* @return object|object[]
|
* @return object|object[]
|
||||||
*/
|
*/
|
||||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = []);
|
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = []);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function extractAttributes($object, $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$reflectionObject = new \ReflectionObject($object);
|
$reflectionObject = new \ReflectionObject($object);
|
||||||
$reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
|
$reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||||
@ -121,7 +121,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$ucfirsted = ucfirst($attribute);
|
$ucfirsted = ucfirst($attribute);
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$setter = 'set'.ucfirst($attribute);
|
$setter = 'set'.ucfirst($attribute);
|
||||||
$key = \get_class($object).':'.$setter;
|
$key = \get_class($object).':'.$setter;
|
||||||
|
@ -52,7 +52,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, string $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
|
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function extractAttributes($object, string $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
// If not using groups, detect manually
|
// If not using groups, detect manually
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
@ -118,7 +118,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getAttributeValue($object, $attribute, string $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$cacheKey = \get_class($object);
|
$cacheKey = \get_class($object);
|
||||||
if (!\array_key_exists($cacheKey, $this->discriminatorCache)) {
|
if (!\array_key_exists($cacheKey, $this->discriminatorCache)) {
|
||||||
@ -135,7 +135,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->propertyAccessor->setValue($object, $attribute, $value);
|
$this->propertyAccessor->setValue($object, $attribute, $value);
|
||||||
@ -147,7 +147,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
protected function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false)
|
||||||
{
|
{
|
||||||
if (false === $allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString)) {
|
if (false === $allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -23,7 +23,7 @@ trait ObjectToPopulateTrait
|
|||||||
*
|
*
|
||||||
* @return object|null an object if things check out, null otherwise
|
* @return object|null an object if things check out, null otherwise
|
||||||
*/
|
*/
|
||||||
protected function extractObjectToPopulate($class, array $context, $key = null)
|
protected function extractObjectToPopulate(string $class, array $context, string $key = null)
|
||||||
{
|
{
|
||||||
$key = $key ?? AbstractNormalizer::OBJECT_TO_POPULATE;
|
$key = $key ?? AbstractNormalizer::OBJECT_TO_POPULATE;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, string $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
|
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
|
if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
|
||||||
return false;
|
return false;
|
||||||
@ -97,7 +97,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function extractAttributes($object, string $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$reflectionObject = new \ReflectionObject($object);
|
$reflectionObject = new \ReflectionObject($object);
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
@ -118,7 +118,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getAttributeValue($object, $attribute, string $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
|
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
|
||||||
@ -137,7 +137,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
|
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
|
||||||
|
@ -109,7 +109,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
final public function serialize($data, $format, array $context = [])
|
final public function serialize($data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
if (!$this->supportsEncoding($format, $context)) {
|
if (!$this->supportsEncoding($format, $context)) {
|
||||||
throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format));
|
throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format));
|
||||||
@ -125,7 +125,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
final public function deserialize($data, $type, $format, array $context = [])
|
final public function deserialize($data, string $type, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
if (!$this->supportsDecoding($format, $context)) {
|
if (!$this->supportsDecoding($format, $context)) {
|
||||||
throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format));
|
throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format));
|
||||||
@ -139,7 +139,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($data, $format = null, array $context = [])
|
public function normalize($data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
// If a normalizer supports the given data, use it
|
// If a normalizer supports the given data, use it
|
||||||
if ($normalizer = $this->getNormalizer($data, $format, $context)) {
|
if ($normalizer = $this->getNormalizer($data, $format, $context)) {
|
||||||
@ -175,7 +175,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
*
|
*
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (!$this->normalizers) {
|
if (!$this->normalizers) {
|
||||||
throw new LogicException('You must register at least one normalizer to be able to denormalize objects.');
|
throw new LogicException('You must register at least one normalizer to be able to denormalize objects.');
|
||||||
@ -191,7 +191,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null, array $context = [])
|
public function supportsNormalization($data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return null !== $this->getNormalizer($data, $format, $context);
|
return null !== $this->getNormalizer($data, $format, $context);
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null, array $context = [])
|
public function supportsDenormalization($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return null !== $this->getDenormalizer($data, $type, $format, $context);
|
return null !== $this->getDenormalizer($data, $type, $format, $context);
|
||||||
}
|
}
|
||||||
@ -282,7 +282,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
final public function encode($data, $format, array $context = [])
|
final public function encode($data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
return $this->encoder->encode($data, $format, $context);
|
return $this->encoder->encode($data, $format, $context);
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
final public function decode($data, $format, array $context = [])
|
final public function decode(string $data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
return $this->decoder->decode($data, $format, $context);
|
return $this->decoder->decode($data, $format, $context);
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsEncoding($format, array $context = [])
|
public function supportsEncoding(string $format, array $context = [])
|
||||||
{
|
{
|
||||||
return $this->encoder->supportsEncoding($format, $context);
|
return $this->encoder->supportsEncoding($format, $context);
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDecoding($format, array $context = [])
|
public function supportsDecoding(string $format, array $context = [])
|
||||||
{
|
{
|
||||||
return $this->decoder->supportsDecoding($format, $context);
|
return $this->decoder->supportsDecoding($format, $context);
|
||||||
}
|
}
|
||||||
|
@ -124,12 +124,12 @@ class ChainNormalizationAwareEncoder extends ChainEncoder implements Normalizati
|
|||||||
|
|
||||||
class NormalizationAwareEncoder implements EncoderInterface, NormalizationAwareInterface
|
class NormalizationAwareEncoder implements EncoderInterface, NormalizationAwareInterface
|
||||||
{
|
{
|
||||||
public function supportsEncoding($format)
|
public function supportsEncoding(string $format)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function encode($data, $format, array $context = [])
|
public function encode($data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class AbstractNormalizerDummy extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
public function getAllowedAttributes($classOrObject, array $context, bool $attributesAsString = false)
|
||||||
{
|
{
|
||||||
return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString);
|
return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString);
|
||||||
}
|
}
|
||||||
@ -31,14 +31,14 @@ class AbstractNormalizerDummy extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($object, $format = null, array $context = [])
|
public function normalize($object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, string $format = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,14 +46,14 @@ class AbstractNormalizerDummy extends AbstractNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
|||||||
|
|
||||||
class DenormalizableDummy implements DenormalizableInterface
|
class DenormalizableDummy implements DenormalizableInterface
|
||||||
{
|
{
|
||||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = [])
|
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface
|
|||||||
public $baz;
|
public $baz;
|
||||||
public $qux;
|
public $qux;
|
||||||
|
|
||||||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
|
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'foo' => $this->foo,
|
'foo' => $this->foo,
|
||||||
@ -33,7 +33,7 @@ class Dummy implements NormalizableInterface, DenormalizableInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = [])
|
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$this->foo = $data['foo'];
|
$this->foo = $data['foo'];
|
||||||
$this->bar = $data['bar'];
|
$this->bar = $data['bar'];
|
||||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|||||||
|
|
||||||
class NormalizableTraversableDummy extends TraversableDummy implements NormalizableInterface, DenormalizableInterface
|
class NormalizableTraversableDummy extends TraversableDummy implements NormalizableInterface, DenormalizableInterface
|
||||||
{
|
{
|
||||||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
|
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'foo' => 'normalizedFoo',
|
'foo' => 'normalizedFoo',
|
||||||
@ -26,7 +26,7 @@ class NormalizableTraversableDummy extends TraversableDummy implements Normaliza
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = [])
|
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'foo' => 'denormalizedFoo',
|
'foo' => 'denormalizedFoo',
|
||||||
|
@ -21,12 +21,12 @@ class ScalarDummy implements NormalizableInterface, DenormalizableInterface
|
|||||||
public $foo;
|
public $foo;
|
||||||
public $xmlFoo;
|
public $xmlFoo;
|
||||||
|
|
||||||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
|
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return 'xml' === $format ? $this->xmlFoo : $this->foo;
|
return 'xml' === $format ? $this->xmlFoo : $this->foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = [])
|
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if ('xml' === $format) {
|
if ('xml' === $format) {
|
||||||
$this->xmlFoo = $data;
|
$this->xmlFoo = $data;
|
||||||
|
@ -21,7 +21,7 @@ class StaticConstructorNormalizer extends ObjectNormalizer
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function getConstructor(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
|
protected function getConstructor(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes)
|
||||||
{
|
{
|
||||||
if (is_a($class, StaticConstructorDummy::class, true)) {
|
if (is_a($class, StaticConstructorDummy::class, true)) {
|
||||||
return new \ReflectionMethod($class, 'create');
|
return new \ReflectionMethod($class, 'create');
|
||||||
|
@ -19,7 +19,7 @@ use Symfony\Component\Serializer\Mapping\ClassMetadata;
|
|||||||
*/
|
*/
|
||||||
class TestClassMetadataFactory
|
class TestClassMetadataFactory
|
||||||
{
|
{
|
||||||
public static function createClassMetadata($withParent = false, $withInterface = false)
|
public static function createClassMetadata(bool $withParent = false, bool $withInterface = false)
|
||||||
{
|
{
|
||||||
$expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
|
$expected = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');
|
||||||
|
|
||||||
|
@ -214,26 +214,26 @@ class AbstractObjectNormalizerTest extends TestCase
|
|||||||
|
|
||||||
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
||||||
{
|
{
|
||||||
protected function extractAttributes($object, $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$object->$attribute = $value;
|
$object->$attribute = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
|
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return \in_array($attribute, ['foo', 'baz', 'quux', 'value']);
|
return \in_array($attribute, ['foo', 'baz', 'quux', 'value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
public function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
||||||
{
|
{
|
||||||
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
|
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
|
||||||
}
|
}
|
||||||
@ -257,15 +257,15 @@ class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
|
|||||||
parent::__construct(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())));
|
parent::__construct(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function extractAttributes($object, $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$object->$attribute = $value;
|
$object->$attribute = $value;
|
||||||
}
|
}
|
||||||
@ -289,20 +289,20 @@ class SerializerCollectionDummy implements SerializerInterface, DenormalizerInte
|
|||||||
/**
|
/**
|
||||||
* @param DenormalizerInterface[] $normalizers
|
* @param DenormalizerInterface[] $normalizers
|
||||||
*/
|
*/
|
||||||
public function __construct($normalizers)
|
public function __construct(array $normalizers)
|
||||||
{
|
{
|
||||||
$this->normalizers = $normalizers;
|
$this->normalizers = $normalizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serialize($data, $format, array $context = [])
|
public function serialize($data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deserialize($data, $type, $format, array $context = [])
|
public function deserialize($data, string $type, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
foreach ($this->normalizers as $normalizer) {
|
foreach ($this->normalizers as $normalizer) {
|
||||||
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format, $context)) {
|
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $type, $format, $context)) {
|
||||||
@ -311,7 +311,7 @@ class SerializerCollectionDummy implements SerializerInterface, DenormalizerInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsDenormalization($data, $type, $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -319,34 +319,34 @@ class SerializerCollectionDummy implements SerializerInterface, DenormalizerInte
|
|||||||
|
|
||||||
class AbstractObjectNormalizerCollectionDummy extends AbstractObjectNormalizer
|
class AbstractObjectNormalizerCollectionDummy extends AbstractObjectNormalizer
|
||||||
{
|
{
|
||||||
protected function extractAttributes($object, $format = null, array $context = [])
|
protected function extractAttributes(object $object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
|
protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$object->$attribute = $value;
|
$object->$attribute = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
|
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
public function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
|
||||||
{
|
{
|
||||||
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
|
return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serialize($data, $format, array $context = [])
|
public function serialize($data, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deserialize($data, $type, $format, array $context = [])
|
public function deserialize($data, string $type, string $format, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareIn
|
|||||||
*
|
*
|
||||||
* @throws NotNormalizableValueException
|
* @throws NotNormalizableValueException
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$serializer = $this->serializer;
|
$serializer = $this->serializer;
|
||||||
$type = substr($type, 0, -2);
|
$type = substr($type, 0, -2);
|
||||||
@ -378,7 +378,7 @@ class ArrayDenormalizerDummy implements DenormalizerInterface, SerializerAwareIn
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null, array $context = [])
|
public function supportsDenormalization($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return '[]' === substr($type, -2)
|
return '[]' === substr($type, -2)
|
||||||
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
|
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
|
||||||
|
@ -599,12 +599,12 @@ class ObjectNormalizerTest extends TestCase
|
|||||||
public function testAdvancedNameConverter()
|
public function testAdvancedNameConverter()
|
||||||
{
|
{
|
||||||
$nameConverter = new class() implements AdvancedNameConverterInterface {
|
$nameConverter = new class() implements AdvancedNameConverterInterface {
|
||||||
public function normalize($propertyName, string $class = null, string $format = null, array $context = [])
|
public function normalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
|
||||||
{
|
{
|
||||||
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize($propertyName, string $class = null, string $format = null, array $context = [])
|
public function denormalize(string $propertyName, string $class = null, string $format = null, array $context = []): string
|
||||||
{
|
{
|
||||||
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
return sprintf('%s-%s-%s-%s', $propertyName, $class, $format, $context['foo']);
|
||||||
}
|
}
|
||||||
@ -833,7 +833,7 @@ class ObjectInner
|
|||||||
|
|
||||||
class FormatAndContextAwareNormalizer extends ObjectNormalizer
|
class FormatAndContextAwareNormalizer extends ObjectNormalizer
|
||||||
{
|
{
|
||||||
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = [])
|
protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if (\in_array($attribute, ['foo', 'bar']) && 'foo_and_bar_included' === $format) {
|
if (\in_array($attribute, ['foo', 'bar']) && 'foo_and_bar_included' === $format) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -23,14 +23,14 @@ class TestDenormalizer implements DenormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, string $type, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = null)
|
public function supportsDenormalization($data, string $type, string $format = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,14 @@ class TestNormalizer implements NormalizerInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function normalize($object, $format = null, array $context = [])
|
public function normalize($object, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsNormalization($data, $format = null)
|
public function supportsNormalization($data, string $format = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user