Skip to content

Commit 9de526d

Browse files
committed
Add deprecation notice
Update changelog
1 parent fbfef89 commit 9de526d

File tree

11 files changed

+85
-88
lines changed

11 files changed

+85
-88
lines changed

src/Symfony/Bridge/Twig/Tests/Mime/TemplatedEmailTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testSymfonySerialize()
102102
EOF;
103103

104104
$extractor = new PhpDocExtractor();
105-
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor);
105+
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor, null, null, [], true);
106106
$serializer = new Serializer([
107107
new ArrayDenormalizer(),
108108
new MimeMessageNormalizer($propertyNormalizer),

src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
139139
null,
140140
[],
141+
false,
141142
])
142143

143144
->alias(PropertyNormalizer::class, 'serializer.normalizer.property')

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ public function testSymfonySerialize()
524524
EOF;
525525

526526
$extractor = new PhpDocExtractor();
527-
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor);
527+
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor, null, null, [], true);
528528
$serializer = new Serializer([
529529
new ArrayDenormalizer(),
530530
new MimeMessageNormalizer($propertyNormalizer),

src/Symfony/Component/Mime/Tests/MessageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testSymfonySerialize()
245245
EOF;
246246

247247
$extractor = new PhpDocExtractor();
248-
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor);
248+
$propertyNormalizer = new PropertyNormalizer(null, null, $extractor, null, null, [], true);
249249
$serializer = new Serializer([
250250
new ArrayDenormalizer(),
251251
new MimeMessageNormalizer($propertyNormalizer),

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CHANGELOG
77
* Add support for constructor promoted properties to `Context` attribute
88
* Add context option `PropertyNormalizer::NORMALIZE_VISIBILITY` with bitmask flags `PropertyNormalizer::NORMALIZE_PUBLIC`, `PropertyNormalizer::NORMALIZE_PROTECTED`, `PropertyNormalizer::NORMALIZE_PRIVATE`
99
* Add method `withNormalizeVisibility` to `PropertyNormalizerContextBuilder`
10+
* Add `allowNormalizationOfObjectsWithoutAnyProperties` option to `PropertyNormalizer`
11+
* Add `allowNormalizationOfObjectsWithoutAnyGetters` option to `GetSetMethodNormalizer`
1012

1113
6.1
1214
---

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function __construct(
5454
) {
5555
parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor, $classDiscriminatorResolver, $objectClassResolver, $defaultContext);
5656
$this->allowNormalizationOfObjectsWithoutAnyGetters = $allowNormalizationOfObjectsWithoutAnyGetters;
57+
58+
if (\func_num_args() < 7) {
59+
trigger_deprecation('symfony/serializer', '6.2', '$allowNormalizationOfObjectsWithoutAnyGetters parameter of %s() should be explicitly provided since the default value will change to `true` in symfony/serializer >=7.0', __METHOD__);
60+
}
5761
}
5862

5963
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
5656
}
5757

5858
$this->allowNormalizationOfObjectsWithoutAnyProperties = $allowNormalizationOfObjectsWithoutAnyProperties;
59+
60+
if (\func_num_args() < 7) {
61+
trigger_deprecation('symfony/serializer', '6.2', '$allowNormalizationOfObjectsWithoutAnyProperties parameter of %s() should be explicitly provided since the default value will change to `true` in symfony/serializer >=7.0', __METHOD__);
62+
}
5963
}
6064

6165
/**

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public function getNormalizer()
205205
{
206206
$extractor = new PhpDocExtractor();
207207

208-
yield [new PropertyNormalizer()];
209-
yield [new PropertyNormalizer(null, null, $extractor)];
208+
yield [new PropertyNormalizer(null, null, null, null, null, [], true)];
209+
yield [new PropertyNormalizer(null, null, $extractor, null, null, [], true)];
210210
yield [new ObjectNormalizer()];
211211
yield [new ObjectNormalizer(null, null, null, $extractor)];
212212
}
@@ -222,7 +222,7 @@ public function testIgnore()
222222
$dummy = new IgnoreDummy();
223223
$dummy->ignored1 = 'hello';
224224

225-
$normalizer = new PropertyNormalizer($this->classMetadata);
225+
$normalizer = new PropertyNormalizer($this->classMetadata, null, null, null, null, [], true);
226226

227227
$this->assertSame([], $normalizer->normalize($dummy));
228228
}

src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function setUp(): void
7373
private function createNormalizer(array $defaultContext = [])
7474
{
7575
$this->serializer = $this->createMock(SerializerNormalizer::class);
76-
$this->normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext);
76+
$this->normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext, true);
7777
$this->normalizer->setSerializer($this->serializer);
7878
}
7979

@@ -234,20 +234,20 @@ protected function getNormalizerForCallbacksWithPropertyTypeExtractor(): GetSetM
234234
{
235235
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
236236

237-
return new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), $this->getCallbackPropertyTypeExtractor());
237+
return new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), $this->getCallbackPropertyTypeExtractor(), null, null, [], true);
238238
}
239239

240240
protected function getNormalizerForCallbacks(): GetSetMethodNormalizer
241241
{
242242
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
243243

244-
return new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory));
244+
return new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), null, null, null, [], true);
245245
}
246246

247247
protected function getNormalizerForCircularReference(array $defaultContext): GetSetMethodNormalizer
248248
{
249249
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
250-
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), null, null, null, $defaultContext);
250+
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), null, null, null, $defaultContext, true);
251251
new Serializer([$normalizer]);
252252

253253
return $normalizer;
@@ -261,7 +261,7 @@ protected function getSelfReferencingModel()
261261
protected function getDenormalizerForConstructArguments(): GetSetMethodNormalizer
262262
{
263263
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
264-
$denormalizer = new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory));
264+
$denormalizer = new GetSetMethodNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory), null, null, null, [], true);
265265
new Serializer([$denormalizer]);
266266

267267
return $denormalizer;
@@ -271,20 +271,20 @@ protected function getNormalizerForGroups(): GetSetMethodNormalizer
271271
{
272272
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
273273

274-
return new GetSetMethodNormalizer($classMetadataFactory);
274+
return new GetSetMethodNormalizer($classMetadataFactory, null, null, null, null, [], true);
275275
}
276276

277277
protected function getDenormalizerForGroups(): GetSetMethodNormalizer
278278
{
279279
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
280280

281-
return new GetSetMethodNormalizer($classMetadataFactory);
281+
return new GetSetMethodNormalizer($classMetadataFactory, null, null, null, null, [], true);
282282
}
283283

284284
public function testGroupsNormalizeWithNameConverter()
285285
{
286286
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
287-
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
287+
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter(), null, null, null, [], true);
288288
$this->normalizer->setSerializer($this->serializer);
289289

290290
$obj = new GroupDummy();
@@ -305,7 +305,7 @@ public function testGroupsNormalizeWithNameConverter()
305305
public function testGroupsDenormalizeWithNameConverter()
306306
{
307307
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
308-
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
308+
$this->normalizer = new GetSetMethodNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter(), null, null, null, [], true);
309309
$this->normalizer->setSerializer($this->serializer);
310310

311311
$obj = new GroupDummy();
@@ -326,7 +326,7 @@ public function testGroupsDenormalizeWithNameConverter()
326326
protected function getNormalizerForMaxDepth(): NormalizerInterface
327327
{
328328
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
329-
$normalizer = new GetSetMethodNormalizer($classMetadataFactory);
329+
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, null, null, null, [], true);
330330
$serializer = new Serializer([$normalizer]);
331331
$normalizer->setSerializer($serializer);
332332

@@ -336,7 +336,7 @@ protected function getNormalizerForMaxDepth(): NormalizerInterface
336336
protected function getDenormalizerForObjectToPopulate(): DenormalizerInterface
337337
{
338338
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
339-
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor());
339+
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor(), null, null, [], true);
340340
new Serializer([$normalizer]);
341341

342342
return $normalizer;
@@ -345,7 +345,7 @@ protected function getDenormalizerForObjectToPopulate(): DenormalizerInterface
345345
protected function getDenormalizerForTypeEnforcement(): DenormalizerInterface
346346
{
347347
$extractor = new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]);
348-
$normalizer = new GetSetMethodNormalizer(null, null, $extractor);
348+
$normalizer = new GetSetMethodNormalizer(null, null, $extractor, null, null, [], true);
349349
$serializer = new Serializer([new ArrayDenormalizer(), $normalizer]);
350350
$normalizer->setSerializer($serializer);
351351

@@ -357,40 +357,32 @@ public function testRejectInvalidKey()
357357
$this->markTestSkipped('This test makes no sense with the GetSetMethodNormalizer');
358358
}
359359

360-
protected function getNormalizerAllowingObjectsWithoutGetters(): GetSetMethodNormalizer
361-
{
362-
return new GetSetMethodNormalizer(null, null, null, null, null, [], true);
363-
}
364-
365360
public function testNormalizeObjectWithoutAnyProperties()
366361
{
367-
$normalizer = $this->getNormalizerAllowingObjectsWithoutGetters();
368362
$obj = new EmptyObjectDummy();
369363

370-
$this->assertTrue($normalizer->supportsNormalization($obj));
371-
364+
$this->assertTrue($this->normalizer->supportsNormalization($obj));
372365
$this->assertEquals(
373366
[],
374-
$normalizer->normalize($obj),
367+
$this->normalizer->normalize($obj),
375368
);
376369
}
377370

378371
public function testDenormalizeObjectWithoutAnyProperties()
379372
{
380-
$normalizer = $this->getNormalizerAllowingObjectsWithoutGetters();
381373
$obj = new EmptyObjectDummy();
382374

383-
$this->assertTrue($normalizer->supportsDenormalization($obj, \get_class($obj)));
375+
$this->assertTrue($this->normalizer->supportsDenormalization($obj, \get_class($obj)));
384376
$this->assertEquals(
385377
$obj,
386-
$normalizer->denormalize([], \get_class($obj)),
378+
$this->normalizer->denormalize([], \get_class($obj)),
387379
);
388380
}
389381

390382
protected function getNormalizerForIgnoredAttributes(): GetSetMethodNormalizer
391383
{
392384
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
393-
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor());
385+
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor(), null, null, [], true);
394386
new Serializer([$normalizer]);
395387

396388
return $normalizer;
@@ -399,7 +391,7 @@ protected function getNormalizerForIgnoredAttributes(): GetSetMethodNormalizer
399391
protected function getDenormalizerForIgnoredAttributes(): GetSetMethodNormalizer
400392
{
401393
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
402-
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor());
394+
$normalizer = new GetSetMethodNormalizer($classMetadataFactory, null, new PhpDocExtractor(), null, null, [], true);
403395
new Serializer([$normalizer]);
404396

405397
return $normalizer;
@@ -457,7 +449,8 @@ public function testNoTraversableSupport()
457449

458450
public function testNoStaticGetSetSupport()
459451
{
460-
$this->assertFalse($this->normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
452+
$normalizer = new GetSetMethodNormalizer(null, null, null, null, null, [], false);
453+
$this->assertFalse($normalizer->supportsNormalization(new ObjectWithJustStaticSetterDummy()));
461454
}
462455

463456
public function testPrivateSetter()
@@ -496,12 +489,12 @@ protected function getObjectCollectionWithExpectedArray(): array
496489

497490
protected function getNormalizerForCacheableObjectAttributesTest(): GetSetMethodNormalizer
498491
{
499-
return new GetSetMethodNormalizer();
492+
return new GetSetMethodNormalizer(null, null, null, null, null, [], true);
500493
}
501494

502495
protected function getNormalizerForSkipUninitializedValues(): NormalizerInterface
503496
{
504-
return new GetSetMethodNormalizer(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())));
497+
return new GetSetMethodNormalizer(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())), null, null, null, null, [], true);
505498
}
506499
}
507500

0 commit comments

Comments
 (0)