From da3411d19888371fb3b043993dc68d58a90e2c8f Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 9 Apr 2019 07:40:56 +0200 Subject: [PATCH] deprecate calling createChildContext without the format parameter --- .../Component/Serializer/Normalizer/AbstractNormalizer.php | 6 +++++- .../Serializer/Normalizer/AbstractObjectNormalizer.php | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index cae8593c15954..1977e9342e300 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -486,8 +486,12 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara * * @internal */ - protected function createChildContext(array $parentContext, $attribute/*, string $format = null */) + protected function createChildContext(array $parentContext, $attribute/*, ?string $format */) { + if (\func_num_args() < 3) { + @trigger_error(sprintf('Method "%s::%s()" will have a 3rd "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED); + $format = null; + } if (isset($parentContext[self::ATTRIBUTES][$attribute])) { $parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute]; } else { diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index cb92412ecc03b..104011bcfedea 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -512,18 +512,19 @@ private function isMaxDepthReached(array $attributesMetadata, string $class, str * We must not mix up the attribute cache between parent and children. * * {@inheritdoc} + * + * @param string|null $format */ - protected function createChildContext(array $parentContext, $attribute/*, string $format = null */) + protected function createChildContext(array $parentContext, $attribute/*, ?string $format */) { if (\func_num_args() >= 3) { $format = \func_get_arg(2); } else { - // will be deprecated in version 4 + @trigger_error(sprintf('Method "%s::%s()" will have a 3rd "?string $format" argument in version 5.0; not defining it is deprecated since Symfony 4.3.', \get_class($this), __FUNCTION__), E_USER_DEPRECATED); $format = null; } $context = parent::createChildContext($parentContext, $attribute, $format); - // format is already included in the cache_key of the parent. $context['cache_key'] = $this->getCacheKey($format, $context); return $context;