[Serializer] [5.0] Add type-hints to serializer interface
This commit is contained in:
parent
cf8cfebd5e
commit
68b588cf45
|
@ -35,7 +35,7 @@ class ChainDecoder implements ContextAwareDecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
final public function decode($data, $format, array $context = [])
|
||||
final public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
return $this->getDecoder($format, $context)->decode($data, $format, $context);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class ChainDecoder implements ContextAwareDecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDecoding($format, array $context = []): bool
|
||||
public function supportsDecoding(string $format, array $context = []): bool
|
||||
{
|
||||
try {
|
||||
$this->getDecoder($format, $context);
|
||||
|
|
|
@ -35,7 +35,7 @@ class ChainEncoder implements ContextAwareEncoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
final public function encode($data, $format, array $context = [])
|
||||
final public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
return $this->getEncoder($format, $context)->encode($data, $format, $context);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class ChainEncoder implements ContextAwareEncoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsEncoding($format, array $context = []): bool
|
||||
public function supportsEncoding(string $format, array $context = []): bool
|
||||
{
|
||||
try {
|
||||
$this->getEncoder($format, $context);
|
||||
|
@ -56,11 +56,8 @@ class ChainEncoder implements ContextAwareEncoderInterface
|
|||
|
||||
/**
|
||||
* Checks whether the normalization is needed for the given format.
|
||||
*
|
||||
* @param string $format
|
||||
* @param array $context
|
||||
*/
|
||||
public function needsNormalization($format, array $context = []): bool
|
||||
public function needsNormalization(string $format, array $context = []): bool
|
||||
{
|
||||
$encoder = $this->getEncoder($format, $context);
|
||||
|
||||
|
|
|
@ -23,5 +23,5 @@ interface ContextAwareDecoderInterface extends DecoderInterface
|
|||
*
|
||||
* @param array $context options that decoders have access to
|
||||
*/
|
||||
public function supportsDecoding($format, array $context = []);
|
||||
public function supportsDecoding(string $format, array $context = []);
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@ interface ContextAwareEncoderInterface extends EncoderInterface
|
|||
*
|
||||
* @param array $context options that encoders have access to
|
||||
*/
|
||||
public function supportsEncoding($format, array $context = []);
|
||||
public function supportsEncoding(string $format, array $context = []);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data, $format, array $context = [])
|
||||
public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
$handle = fopen('php://temp,', 'w+');
|
||||
|
||||
|
@ -110,7 +110,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($data, $format, array $context = [])
|
||||
public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
$handle = fopen('php://temp', 'r+');
|
||||
fwrite($handle, $data);
|
||||
|
|
|
@ -36,7 +36,7 @@ interface DecoderInterface
|
|||
*
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function decode($data, $format, array $context = []);
|
||||
public function decode(string $data, string $format, array $context = []);
|
||||
|
||||
/**
|
||||
* Checks whether the deserializer can decode from given format.
|
||||
|
@ -45,5 +45,5 @@ interface DecoderInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsDecoding($format);
|
||||
public function supportsDecoding(string $format);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ interface EncoderInterface
|
|||
*
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function encode($data, $format, array $context = []);
|
||||
public function encode($data, string $format, array $context = []);
|
||||
|
||||
/**
|
||||
* Checks whether the serializer can encode to given format.
|
||||
|
@ -40,5 +40,5 @@ interface EncoderInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsEncoding($format);
|
||||
public function supportsEncoding(string $format);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class JsonDecode implements DecoderInterface
|
|||
*
|
||||
* @see http://php.net/json_decode json_decode
|
||||
*/
|
||||
public function decode($data, $format, array $context = [])
|
||||
public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
|
||||
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
|
||||
|
@ -98,7 +98,7 @@ class JsonDecode implements DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDecoding($format)
|
||||
public function supportsDecoding(string $format)
|
||||
{
|
||||
return JsonEncoder::FORMAT === $format;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class JsonEncode implements EncoderInterface
|
|||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data, $format, array $context = [])
|
||||
public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
|
||||
$encodedJson = json_encode($data, $jsonEncodeOptions);
|
||||
|
@ -55,7 +55,7 @@ class JsonEncode implements EncoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsEncoding($format)
|
||||
public function supportsEncoding(string $format)
|
||||
{
|
||||
return JsonEncoder::FORMAT === $format;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data, $format, array $context = [])
|
||||
public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
return $this->encodingImpl->encode($data, self::FORMAT, $context);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($data, $format, array $context = [])
|
||||
public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
return $this->decodingImpl->decode($data, self::FORMAT, $context);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsEncoding($format)
|
||||
public function supportsEncoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class JsonEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDecoding($format)
|
||||
public function supportsDecoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data, $format, array $context = [])
|
||||
public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
|
||||
$ignorePiNode = \in_array(XML_PI_NODE, $encoderIgnoredNodeTypes, true);
|
||||
|
@ -107,7 +107,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($data, $format, array $context = [])
|
||||
public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
if ('' === trim($data)) {
|
||||
throw new NotEncodableValueException('Invalid XML data, it can not be empty.');
|
||||
|
@ -176,7 +176,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsEncoding($format)
|
||||
public function supportsEncoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDecoding($format)
|
||||
public function supportsDecoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data, $format, array $context = [])
|
||||
public function encode($data, string $format, array $context = [])
|
||||
{
|
||||
$context = array_merge($this->defaultContext, $context);
|
||||
|
||||
|
@ -53,7 +53,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsEncoding($format)
|
||||
public function supportsEncoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function decode($data, $format, array $context = [])
|
||||
public function decode(string $data, string $format, array $context = [])
|
||||
{
|
||||
$context = array_merge($this->defaultContext, $context);
|
||||
|
||||
|
@ -71,7 +71,7 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDecoding($format)
|
||||
public function supportsDecoding(string $format)
|
||||
{
|
||||
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ interface AttributeMetadataInterface
|
|||
*
|
||||
* @param string $group
|
||||
*/
|
||||
public function addGroup($group);
|
||||
public function addGroup(string $group);
|
||||
|
||||
/**
|
||||
* Gets groups of this attribute.
|
||||
|
@ -48,7 +48,7 @@ interface AttributeMetadataInterface
|
|||
*
|
||||
* @param int|null $maxDepth
|
||||
*/
|
||||
public function setMaxDepth($maxDepth);
|
||||
public function setMaxDepth(?int $maxDepth);
|
||||
|
||||
/**
|
||||
* Gets the serialization max depth for this attribute.
|
||||
|
|
|
@ -34,7 +34,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($propertyName)
|
||||
public function normalize(string $propertyName)
|
||||
{
|
||||
if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
|
||||
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
|
||||
|
@ -46,7 +46,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function denormalize($propertyName)
|
||||
public function denormalize(string $propertyName)
|
||||
{
|
||||
$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
|
||||
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
|
||||
|
|
|
@ -25,7 +25,7 @@ interface NameConverterInterface
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function normalize($propertyName);
|
||||
public function normalize(string $propertyName);
|
||||
|
||||
/**
|
||||
* Converts a property name to its denormalized value.
|
||||
|
@ -34,5 +34,5 @@ interface NameConverterInterface
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function denormalize($propertyName);
|
||||
public function denormalize(string $propertyName);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return \is_object($data) && !$data instanceof \Traversable;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!isset($context['cache_key'])) {
|
||||
$context['cache_key'] = $this->getCacheKey($format, $context);
|
||||
|
@ -233,7 +233,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getAttributes($object, $format = null, array $context)
|
||||
protected function getAttributes($object, string $format = null, array $context)
|
||||
{
|
||||
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
|
||||
$key = $class.'-'.$context['cache_key'];
|
||||
|
@ -274,7 +274,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
*
|
||||
* @return string[]
|
||||
*/
|
||||
abstract protected function extractAttributes($object, $format = null, array $context = []);
|
||||
abstract protected function extractAttributes($object, string $format = null, array $context = []);
|
||||
|
||||
/**
|
||||
* Gets the attribute value.
|
||||
|
@ -286,12 +286,12 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function getAttributeValue($object, $attribute, $format = null, array $context = []);
|
||||
abstract protected function getAttributeValue($object, string $attribute, string $format = null, array $context = []);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
if (!isset($context['cache_key'])) {
|
||||
$context['cache_key'] = $this->getCacheKey($format, $context);
|
||||
|
|
|
@ -23,5 +23,5 @@ interface ContextAwareDenormalizerInterface extends DenormalizerInterface
|
|||
*
|
||||
* @param array $context options that denormalizers have access to
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null, array $context = []);
|
||||
public function supportsDenormalization($data, string $type, string $format = null, array $context = []);
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@ interface ContextAwareNormalizerInterface extends NormalizerInterface
|
|||
*
|
||||
* @param array $context options that normalizers have access to
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null, array $context = []);
|
||||
public function supportsNormalization($data, string $format = null, array $context = []);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
return $object->normalize($this->serializer, $format, $context);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
$object = $this->extractObjectToPopulate($class, $context) ?: new $class();
|
||||
$object->denormalize($this->serializer, $data, $format, $context);
|
||||
|
@ -49,7 +49,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof NormalizableInterface;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return is_subclass_of($type, DenormalizableInterface::class);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof \SplFileInfo) {
|
||||
throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".');
|
||||
|
@ -74,7 +74,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof \SplFileInfo;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||
* @throws InvalidArgumentException
|
||||
* @throws NotNormalizableValueException
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, 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)) {
|
||||
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
|
||||
|
@ -118,7 +118,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface, C
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return isset(self::$supportedTypes[$type]);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof \DateInterval) {
|
||||
throw new InvalidArgumentException('The object must be an instance of "\DateInterval".');
|
||||
|
@ -50,7 +50,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof \DateInterval;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
* @throws InvalidArgumentException
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
if (!\is_string($data)) {
|
||||
throw new InvalidArgumentException(sprintf('Data expected to be a string, %s given.', \gettype($data)));
|
||||
|
@ -96,7 +96,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return \DateInterval::class === $type;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof \DateTimeInterface) {
|
||||
throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
|
||||
|
@ -66,7 +66,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof \DateTimeInterface;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||
*
|
||||
* @throws NotNormalizableValueException
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
$dateTimeFormat = $context[self::FORMAT_KEY] ?? null;
|
||||
$timezone = $this->getTimezone($context);
|
||||
|
@ -113,7 +113,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface,
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return isset(self::$supportedTypes[$type]);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if (!$object instanceof \DateTimeZone) {
|
||||
throw new InvalidArgumentException('The object must be an instance of "\DateTimeZone".');
|
||||
|
@ -38,7 +38,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof \DateTimeZone;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
*
|
||||
* @throws NotNormalizableValueException
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
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.');
|
||||
|
@ -64,7 +64,7 @@ class DateTimeZoneNormalizer implements NormalizerInterface, DenormalizerInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return \DateTimeZone::class === $type;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ interface DenormalizerInterface
|
|||
* @throws RuntimeException Occurs if the class cannot be instantiated
|
||||
* @throws ExceptionInterface Occurs for all the other cases of errors
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = []);
|
||||
public function denormalize($data, string $class, string $format = null, array $context = []);
|
||||
|
||||
/**
|
||||
* Checks whether the given class is supported for denormalization by this normalizer.
|
||||
|
@ -55,5 +55,5 @@ interface DenormalizerInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null);
|
||||
public function supportsDenormalization($data, string $type, string $format = null);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data));
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = [])
|
||||
public function normalize($object, string $format = null, array $context = [])
|
||||
{
|
||||
if ($this->isCircularReference($object, $context)) {
|
||||
return $this->handleCircularReference($object);
|
||||
|
@ -44,7 +44,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return $data instanceof \JsonSerializable;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function denormalize($data, $class, $format = null, array $context = [])
|
||||
public function denormalize($data, $class, string $format = null, array $context = [])
|
||||
{
|
||||
throw new LogicException(sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
|
||||
}
|
||||
|
|
|
@ -35,5 +35,5 @@ interface NormalizableInterface
|
|||
*
|
||||
* @return array|string|int|float|bool
|
||||
*/
|
||||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []);
|
||||
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ interface NormalizerInterface
|
|||
* @throws LogicException Occurs when the normalizer is not called in an expected context
|
||||
* @throws ExceptionInterface Occurs for all the other cases of errors
|
||||
*/
|
||||
public function normalize($object, $format = null, array $context = []);
|
||||
public function normalize($object, string $format = null, array $context = []);
|
||||
|
||||
/**
|
||||
* Checks whether the given class is supported for normalization by this normalizer.
|
||||
|
@ -48,5 +48,5 @@ interface NormalizerInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null);
|
||||
public function supportsNormalization($data, string $format = null);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function extractAttributes($object, $format = null, array $context = [])
|
||||
protected function extractAttributes($object, string $format = null, array $context = [])
|
||||
{
|
||||
// If not using groups, detect manually
|
||||
$attributes = [];
|
||||
|
@ -118,7 +118,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
||||
protected function getAttributeValue($object, $attribute, string $format = null, array $context = [])
|
||||
{
|
||||
$cacheKey = \get_class($object);
|
||||
if (!\array_key_exists($cacheKey, $this->discriminatorCache)) {
|
||||
|
|
|
@ -33,7 +33,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsNormalization($data, $format = null)
|
||||
public function supportsNormalization($data, string $format = null)
|
||||
{
|
||||
return parent::supportsNormalization($data, $format) && $this->supports(\get_class($data));
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
public function supportsDenormalization($data, $type, string $format = null)
|
||||
{
|
||||
return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function extractAttributes($object, $format = null, array $context = [])
|
||||
protected function extractAttributes($object, string $format = null, array $context = [])
|
||||
{
|
||||
$reflectionObject = new \ReflectionObject($object);
|
||||
$attributes = [];
|
||||
|
@ -118,7 +118,7 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
|
||||
protected function getAttributeValue($object, $attribute, string $format = null, array $context = [])
|
||||
{
|
||||
try {
|
||||
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
|
||||
|
|
|
@ -27,7 +27,7 @@ interface SerializerInterface
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize($data, $format, array $context = []);
|
||||
public function serialize($data, string $format, array $context = []);
|
||||
|
||||
/**
|
||||
* Deserializes data into the given type.
|
||||
|
@ -39,5 +39,5 @@ interface SerializerInterface
|
|||
*
|
||||
* @return object
|
||||
*/
|
||||
public function deserialize($data, $type, $format, array $context = []);
|
||||
public function deserialize($data, string $type, string $format, array $context = []);
|
||||
}
|
||||
|
|
Reference in New Issue