From 894f99bfe59fc4d0938f5b42b55f68502c1546d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 18 May 2017 08:41:42 +0200 Subject: [PATCH] [Serializer] Remove support for deprecated signatures --- src/Symfony/Component/Serializer/CHANGELOG.md | 3 + .../Normalizer/AbstractNormalizer.php | 15 +---- .../Component/Serializer/Serializer.php | 60 ++----------------- .../AbstractObjectNormalizerTest.php | 2 +- 4 files changed, 9 insertions(+), 71 deletions(-) diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index 250525d8528f3..f6b0c892df7e9 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -8,6 +8,9 @@ CHANGELOG use the `SerializerAwareTrait` instead * removed the `Serializer::$normalizerCache` and `Serializer::$denormalizerCache` properties + * added an optional `string $format = null` argument to `AbstractNormalizer::instantiateObject` + * added an optional `array $context = array()` to `Serializer::supportsNormalization`, `Serializer::supportsDenormalization`, + `Serializer::supportsEncoding` and `Serializer::supportsDecoding` 3.3.0 ----- diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index a6d4fed210068..065ea7d720950 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -305,21 +305,8 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec * * @throws RuntimeException */ - protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes/*, string $format = null*/) + protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null) { - if (func_num_args() >= 6) { - $format = func_get_arg(5); - } else { - if (__CLASS__ !== get_class($this)) { - $r = new \ReflectionMethod($this, __FUNCTION__); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s::%s() will have a 6th `string $format = null` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); - } - } - - $format = null; - } - if ( isset($context[static::OBJECT_TO_POPULATE]) && is_object($context[static::OBJECT_TO_POPULATE]) && diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index cf6663d7195fd..f63c7d5c88e62 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -163,42 +163,16 @@ public function denormalize($data, $type, $format = null, array $context = array /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null/*, array $context = array()*/) + public function supportsNormalization($data, $format = null, array $context = array()) { - if (func_num_args() > 2) { - $context = func_get_arg(2); - } else { - if (__CLASS__ !== get_class($this)) { - $r = new \ReflectionMethod($this, __FUNCTION__); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); - } - } - - $context = array(); - } - return null !== $this->getNormalizer($data, $format, $context); } /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/) + public function supportsDenormalization($data, $type, $format = null, array $context = array()) { - if (func_num_args() > 3) { - $context = func_get_arg(3); - } else { - if (__CLASS__ !== get_class($this)) { - $r = new \ReflectionMethod($this, __FUNCTION__); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); - } - } - - $context = array(); - } - return null !== $this->getDenormalizer($data, $type, $format, $context); } @@ -284,42 +258,16 @@ private function denormalizeObject($data, $class, $format, array $context = arra /** * {@inheritdoc} */ - public function supportsEncoding($format/*, array $context = array()*/) + public function supportsEncoding($format, array $context = array()) { - if (func_num_args() > 1) { - $context = func_get_arg(1); - } else { - if (__CLASS__ !== get_class($this)) { - $r = new \ReflectionMethod($this, __FUNCTION__); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); - } - } - - $context = array(); - } - return $this->encoder->supportsEncoding($format, $context); } /** * {@inheritdoc} */ - public function supportsDecoding($format/*, array $context = array()*/) + public function supportsDecoding($format, array $context = array()) { - if (func_num_args() > 1) { - $context = func_get_arg(1); - } else { - if (__CLASS__ !== get_class($this)) { - $r = new \ReflectionMethod($this, __FUNCTION__); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED); - } - } - - $context = array(); - } - return $this->decoder->supportsDecoding($format, $context); } } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index 1040111cfe620..d58d1843cb0d0 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -73,7 +73,7 @@ protected function isAllowedAttribute($classOrObject, $attribute, $format = null return in_array($attribute, array('foo', 'baz')); } - public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, $format = null) + public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null) { return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format); }