deprecate calling createChildContext without the format parameter

This commit is contained in:
David Buchmann 2019-04-09 07:40:56 +02:00 committed by Fabien Potencier
parent b529e0746a
commit cb77902805
2 changed files with 9 additions and 4 deletions

View File

@ -555,8 +555,12 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
*
* @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 third "?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 {

View File

@ -559,18 +559,19 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* 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 third "?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;