8000 [Serializer] update implementation · symfony/symfony@dcbf8c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit dcbf8c6

Browse filesBrowse files
committed
[Serializer] update implementation
1 parent 9d2699e commit dcbf8c6

21 files changed

+66
-68
lines changed

src/Symfony/Component/Serializer/Encoder/ChainDecoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(array $decoders = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
final public function decode($data, $format, array $context = [])
38+
final public function decode($data, string $format, array $context = [])
3939
{
4040
return $this->getDecoder($format, $context)->decode($data, $format, $context);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function supportsDecoding($format, array $context = []): bool
46+
public function supportsDecoding(string $format, array $context = []): bool
4747
{
4848
try {
4949
$this->getDecoder($format, $context);

src/Symfony/Component/Serializer/Encoder/ChainEncoder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(array $encoders = [])
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
final public function encode($data, $format, array $context = [])
38+
final public function encode($data, string $format, array $context = [])
3939
{
4040
return $this->getEncoder($format, $context)->encode($data, $format, $context);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function supportsEncoding($format, array $context = []): bool
46+
public function supportsEncoding(string $format, array $context = []): bool
4747
{
4848
try {
4949
$this->getEncoder($format, $context);
@@ -57,10 +57,8 @@ public function supportsEncoding($format, array $context = []): bool
5757
/**
5858
* Checks whether the normalization is needed for the given format.
5959
*
60-
* @param string $format
61-
* @param array $context
6260
*/
63-
public function needsNormalization($format, array $context = []): bool
61+
public function needsNormalization(string $format, array $context = []): bool
6462
{
6563
$encoder = $this->getEncoder($format, $context);
6664

src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ContextAwareEncoderInterface extends EncoderInterface
2323
*
2424
* @param array $context options that encoders have access to
2525
*/
26-
public function supportsEncoding($format, array $context = []);
26+
public function supportsEncoding(string $format, array $context = []);
2727
}

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(array $defaultContext = [])
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function encode($data, $format, array $context = [])
54+
public function encode($data, string $format, array $context = [])
5555
{
5656
$handle = fopen('php://temp,', 'w+');
5757

@@ -110,7 +110,7 @@ public function supportsEncoding($format)
110110
/**
111111
* {@inheritdoc}
112112
*/
113-
public function decode($data, $format, array $context = [])
113+
public function decode($data, string $format, array $context = [])
114114
{
115115
$handle = fopen('php://temp', 'r+');
116116
fwrite($handle, $data);

src/Symfony/Component/Serializer/Encoder/JsonDecode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(array $defaultContext = [])
7272
*
7373
* @see http://php.net/json_decode json_decode
7474
*/
75-
public function decode($data, $format, array $context = [])
75+
public function decode($data, string $format, array $context = [])
7676
{
7777
$associative = $context[self::ASSOCIATIVE] ?? $this->defaultContext[self::ASSOCIATIVE];
7878
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
@@ -98,7 +98,7 @@ public function decode($data, $format, array $context = [])
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
public function supportsDecoding($format)
101+
public function supportsDecoding(string $format)
102102
{
103103
return JsonEncoder::FORMAT === $format;
104104
}

src/Symfony/Component/Serializer/Encoder/JsonEncode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(array $defaultContext = [])
3636
*
3737
* {@inheritdoc}
3838
*/
39-
public function encode($data, $format, array $context = [])
39+
public function encode($data, string $format, array $context = [])
4040
{
4141
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
4242
$encodedJson = json_encode($data, $jsonEncodeOptions);
@@ -55,7 +55,7 @@ public function encode($data, $format, array $context = [])
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function supportsEncoding($format)
58+
public function supportsEncoding(string $format)
5959
{
6060
return JsonEncoder::FORMAT === $format;
6161
}

src/Symfony/Component/Serializer/Encoder/JsonEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,31 @@ public function __construct(JsonEncode $encodingImpl = null, JsonDecode $decodin
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function encode($data, $format, array $context = [])
35+
public function encode($data, string $format, array $context = [])
3636
{
3737
return $this->encodingImpl->encode($data, self::FORMAT, $context);
3838
}
3939

4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function decode($data, $format, array $context = [])
43+
public function decode($data, string $format, array $context = [])
4444
{
4545
return $this->decodingImpl->decode($data, self::FORMAT, $context);
4646
}
4747

4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public function supportsEncoding($format)
51+
public function supportsEncoding(string $format)
5252
{
5353
return self::FORMAT === $format;
5454
}
5555

5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function supportsDecoding($format)
59+
public function supportsDecoding(string $format)
6060
{
6161
return self::FORMAT === $format;
6262
}

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(array $defaultContext = [])
7979
/**
8080
* {@inheritdoc}
8181
*/
82-
public function encode($data, $format, array $context = [])
82+
public function encode($data, string $format, array $context = [])
8383
{
8484
$encoderIgnoredNodeTypes = $context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
8585
$ignorePiNode = \in_array(XML_PI_NODE, $encoderIgnoredNodeTypes, true);
@@ -107,7 +107,7 @@ public function encode($data, $format, array $context = [])
107107
/**
108108
* {@inheritdoc}
109109
*/
110-
public function decode($data, $format, array $context = [])
110+
public function decode($data, string $format, array $context = [])
111111
{
112112
if ('' === trim($data)) {
113113
throw new NotEncodableValueException('Invalid XML data, it can not be empty.');
@@ -176,15 +176,15 @@ public function decode($data, $format, array $context = [])
176176
/**
177177
* {@inheritdoc}
178178
*/
179-
public function supportsEncoding($format)
179+
public function supportsEncoding(string $format)
180180
{
181181
return self::FORMAT === $format;
182182
}
183183

184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function supportsDecoding($format)
187+
public function supportsDecoding(string $format)
188188
{
189189
return self::FORMAT === $format;
190190
}

src/Symfony/Component/Serializer/Encoder/YamlEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function encode($data, $format, array $context = [])
46+
public function encode($data, string $format, array $context = [])
4747
{
4848
$context = array_merge($this->defaultContext, $context);
4949

@@ -53,15 +53,15 @@ public function encode($data, $format, array $context = [])
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function supportsEncoding($format)
56+
public function supportsEncoding(string $format)
5757
{
5858
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
5959
}
6060

6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function decode($data, $format, array $context = [])
64+
public function decode($data, string $format, array $context = [])
6565
{
6666
$context = array_merge($this->defaultContext, $context);
6767

@@ -71,7 +71,7 @@ public function decode($data, $format, array $context = [])
7171
/**
7272
* {@inheritdoc}
7373
*/
74-
public function supportsDecoding($format)
74+
public function supportsDecoding(string $format)
7575
{
7676
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
7777
}

src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorResolverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ public function getMappingForMappedObject($object): ?ClassDiscriminatorMapping;
3737
*
3838
* @return string|null
3939
*/
40-
public function getTypeForMappedObject(?string $object): ?string;
40+
public function getTypeForMappedObject($object): ?string;
4141
}

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(array $attributes = null, bool $lowerCamelCase = tru
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function normalize($propertyName)
37+
public function normalize(string $propertyName)
3838
{
3939
if (null === $this->attributes || \in_array($propertyName, $this->attributes)) {
4040
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
@@ -46,7 +46,7 @@ public function normalize($propertyName)
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function denormalize($propertyName)
49+
public function denormalize(string $propertyName)
5050
{
5151
$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', function ($match) {
5252
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
121121
/**
122122
* {@inheritdoc}
123123
*/
124-
public function supportsNormalization($data, $format = null)
124+
public function supportsNormalization($data, ?string $format = null)
125125
{
126126
return \is_object($data) && !$data instanceof \Traversable;
127127
}
128128

129129
/**
130130
* {@inheritdoc}
131131
*/
132-
public function normalize($object, $format = null, array $context = [])
132+
public function normalize($object, ?string $format = null, array $context = [])
133133
{
134134
if (!isset($context['cache_key'])) {
135135
$context['cache_key'] = $this->getCacheKey($format, $context);
@@ -233,7 +233,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
233233
*
234234
* @return string[]
235235
*/
236-
protected function getAttributes($object, $format = null, array $context)
236+
protected function getAttributes($object, ?string $format = null, array $context)
237237
{
238238
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
239239
$key = $class.'-'.$context['cache_key'];
@@ -274,7 +274,7 @@ protected function getAttributes($object, $format = null, array $context)
274274
*
275275
* @return string[]
276276
*/
277-
abstract protected function extractAttributes($object, $format = null, array $context = []);
277+
abstract protected function extractAttributes($object, ?string $format = null, array $context = []);
278278

279279
/**
280280
* Gets the attribute value.
@@ -286,20 +286,20 @@ abstract protected function extractAttributes($object, $format = null, array $co
286286
*
287287
* @return mixed
288288
*/
289-
abstract protected function getAttributeValue($object, $attribute, $format = null, array $context = []);
289+
abstract protected function getAttributeValue($object, string $attribute, ?string $format = null, array $context = []);
290290

291291
/**
292292
* {@inheritdoc}
293293
*/
294-
public function supportsDenormalization($data, $type, $format = null)
294+
public function supportsDenormalization($data, $type, ?string $format = null)
295295
{
296296
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
297297
}
298298

299299
/**
300300
* {@inheritdoc}
301301
*/
302-
public function denormalize($data, $class, $format = null, array $context = [])
302+
public function denormalize($data, $class, ?string $format = null, array $context = [])
303303
{
304304
if (!isset($context['cache_key'])) {
305305
$context['cache_key'] = $this->getCacheKey($format, $context);

src/Symfony/Component/Serializer/Normalizer/CustomNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, Se
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function normalize($object, $format = null, array $context = [])
28+
public function normalize($object, ?string $format = null, array $context = [])
2929
{
3030
return $object->normalize($this->serializer, $format, $context);
3131
}
3232

3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function denormalize($data, $class, $format = null, array $context = [])
36+
public function denormalize($data, $class, ?string $format = null, array $context = [])
3737
{
3838
$object = $this->extractObjectToPopulate($class, $context) ?: new $class();
3939
$object->denormalize($this->serializer, $data, $format, $context);
@@ -49,7 +49,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
4949
*
5050
* @return bool
5151
*/
52-
public function supportsNormalization($data, $format = null)
52+
public function supportsNormalization($data, ?string $format = null)
5353
{
5454
return $data instanceof NormalizableInterface;
5555
}
@@ -63,7 +63,7 @@ public function supportsNormalization($data, $format = null)
6363
*
6464
* @return bool
6565
*/
66-
public function supportsDenormalization($data, $type, $format = null)
66+
public function supportsDenormalization($data, $type, ?string $format = null)
6767
{
6868
return is_subclass_of($type, DenormalizableInterface::class);
6969
}

src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser = null)
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public function normalize($object, $format = null, array $context = [])
51+
public function normalize($object, ?string $format = null, array $context = [])
5252
{
5353
if (!$object instanceof \SplFileInfo) {
5454
throw new InvalidArgumentException('The object must be an instance of "\SplFileInfo".');
@@ -74,7 +74,7 @@ public function normalize($object, $format = null, array $context = [])
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function supportsNormalization($data, $format = null)
77+
public function supportsNormalization($data, ?string $format = null)
7878
{
7979
return $data instanceof \SplFileInfo;
8080
}
@@ -89,7 +89,7 @@ public function supportsNormalization($data, $format = null)
8989
* @throws InvalidArgumentException
9090
* @throws NotNormalizableValueException
9191
*/
92-
public function denormalize($data, $class, $format = null, array $context = [])
92+
public function denormalize($data, $class, ?string $format = null, array $context = [])
9393
{
9494
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)) {
9595
throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
@@ -118,7 +118,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
118118
/**
119119
* {@inheritdoc}
120120
*/
121-
public function supportsDenormalization($data, $type, $format = null)
121+
public function supportsDenormalization($data, $type, ?string $format = null)
122122
{
123123
return isset(self::$supportedTypes[$type]);
124124
}

0 commit comments

Comments
 (0)
0