From 90ba197cefefe5ab2f3d332a5495988c34874b9b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 4 Nov 2016 14:53:25 +0100 Subject: [PATCH] [DI][Serializer] Add missing deprecations --- .../DependencyInjection/Compiler/Compiler.php | 10 ++++++++-- .../DependencyInjection/Compiler/PassConfig.php | 8 +++++++- .../DependencyInjection/ContainerBuilder.php | 3 +-- .../Serializer/Normalizer/AbstractNormalizer.php | 13 ++++++++++++- .../Normalizer/AbstractObjectNormalizerTest.php | 4 ++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index cc5d9adc79..3aa2526399 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -70,12 +70,18 @@ class Compiler * @param string $type The type of the pass * @param int $priority Used to sort the passes */ - public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/**, $priority = 0*/) + public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/) { - // For BC if (func_num_args() >= 3) { $priority = 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 `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + } + } + $priority = 0; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index 8da6595cd9..b95a414829 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -96,10 +96,16 @@ class PassConfig */ public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/) { - // For BC if (func_num_args() >= 3) { $priority = 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 `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED); + } + } + $priority = 0; } diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index bf4f2937a6..964f43bd8b 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -310,9 +310,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface * * @return ContainerBuilder The current instance */ - public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/**, $priority = 0*/) + public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/) { - // For BC if (func_num_args() >= 3) { $priority = func_get_arg(2); } else { diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php index a1aa4250e2..82f6e1e2a8 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php @@ -289,7 +289,18 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N */ protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes/*, $format = null*/) { - $format = func_num_args() >= 6 ? func_get_arg(5) : 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() will have a 6th `$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]) && diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index c9df3c955f..03693fef22 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -59,9 +59,9 @@ class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer return in_array($attribute, array('foo', 'baz')); } - public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes) + public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, $format = null) { - return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes); + return parent::instantiateObject($data, $class, $context, $reflectionClass, $allowedAttributes, $format); } }