Skip to content

Commit ab46a95

Browse files
committed
Merge branch '4.0'
* 4.0: [HttpKernel] Fix race condition when clearing old containers [DI] Fix infinite loop in InlineServiceDefinitionsPass [HttpKernel] Keep legacy container files for concurrent requests Do not cache cache attributes if `attributes` is in the context Test that it do not remove the new flashes when displaying the existing ones [HttpFoundation] AutExpireFlashBag should not clear new flashes [FrameworkBundle][Serializer] Remove YamlEncoder definition if Yaml component isn't installed [DI] Fix tracking of env vars in exceptions [Form] Don't rely on if http-foundation isn't in FileType Fix merge substitute aliases in inline mappings added ability for substitute aliases when mapping in YAML is on single line [Console] Fix global console flag when used in chain
2 parents ef3d5c9 + 7343d18 commit ab46a95

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Normalizer/AbstractObjectNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ protected function getAttributes($object, $format = null, array $context)
129129
return $allowedAttributes;
130130
}
131131

132+
if (isset($context['attributes'])) {
133+
return $this->extractAttributes($object, $format, $context);
134+
}
135+
132136
if (isset($this->attributesCache[$class])) {
133137
return $this->attributesCache[$class];
134138
}

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,37 @@ public function testAttributesContextDenormalizeConstructor()
723723
'inner' => array('foo' => 'foo', 'bar' => 'bar'),
724724
), DummyWithConstructorObjectAndDefaultValue::class, null, $context));
725725
}
726+
727+
public function testNormalizeSameObjectWithDifferentAttributes()
728+
{
729+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
730+
$this->normalizer = new ObjectNormalizer($classMetadataFactory);
731+
$serializer = new Serializer(array($this->normalizer));
732+
$this->normalizer->setSerializer($serializer);
733+
734+
$dummy = new ObjectOuter();
735+
$dummy->foo = new ObjectInner();
736+
$dummy->foo->foo = 'foo.foo';
737+
$dummy->foo->bar = 'foo.bar';
738+
739+
$dummy->bar = new ObjectInner();
740+
$dummy->bar->foo = 'bar.foo';
741+
$dummy->bar->bar = 'bar.bar';
742+
743+
$this->assertEquals(array(
744+
'foo' => array(
745+
'bar' => 'foo.bar',
746+
),
747+
'bar' => array(
748+
'foo' => 'bar.foo',
749+
),
750+
), $this->normalizer->normalize($dummy, 'json', array(
751+
'attributes' => array(
752+
'foo' => array('bar'),
753+
'bar' => array('foo'),
754+
),
755+
)));
756+
}
726757
}
727758

728759
class ObjectDummy

0 commit comments

Comments
 (0)