diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index c9a7da9b81..abac37770e 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -97,11 +97,11 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer $attributeValue = $this->getAttributeValue($object, $attribute, $format, $context); if ($maxDepthReached) { - $attributeValue = \call_user_func($this->maxDepthHandler, $attributeValue); + $attributeValue = \call_user_func($this->maxDepthHandler, $attributeValue, $object, $attribute, $format, $context); } if (isset($this->callbacks[$attribute])) { - $attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue); + $attributeValue = \call_user_func($this->callbacks[$attribute], $attributeValue, $object, $attribute, $format, $context); } if (null !== $attributeValue && !is_scalar($attributeValue)) { diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php index d5d9885f7f..62338af339 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php @@ -426,6 +426,8 @@ class ObjectNormalizerTest extends TestCase array( array( 'bar' => function ($bar) { + $this->assertEquals('baz', $bar); + return 'baz'; }, ), @@ -435,8 +437,12 @@ class ObjectNormalizerTest extends TestCase ), array( array( - 'bar' => function ($bar) { - return; + 'bar' => function ($value, $object, $attributeName, $format, $context) { + $this->assertSame('baz', $value); + $this->assertInstanceOf(ObjectConstructorDummy::class, $object); + $this->assertSame('bar', $attributeName); + $this->assertSame('any', $format); + $this->assertArrayHasKey('circular_reference_limit', $context); }, ), 'baz', @@ -634,6 +640,18 @@ class ObjectNormalizerTest extends TestCase $result = $serializer->normalize($level1, null, array(ObjectNormalizer::ENABLE_MAX_DEPTH => true)); $this->assertEquals($expected, $result); + + $this->normalizer->setMaxDepthHandler(function ($object, $parentObject, $attributeName, $format, $context) { + $this->assertSame('level3', $object); + $this->assertInstanceOf(MaxDepthDummy::class, $parentObject); + $this->assertSame('foo', $attributeName); + $this->assertSame('test', $format); + $this->assertArrayHasKey(ObjectNormalizer::ENABLE_MAX_DEPTH, $context); + + return 'handler'; + }); + + $serializer->normalize($level1, 'test', array(ObjectNormalizer::ENABLE_MAX_DEPTH => true)); } /** diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php index 29c2127a27..ffcbacd063 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php @@ -276,7 +276,6 @@ class PropertyNormalizerTest extends TestCase array( array( 'bar' => function ($bar) { - return; }, ), 'baz',