diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 07919b74d9fdf..5d968148e213d 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -303,9 +303,28 @@ private function getReflectionClass($id, Definition $definition) $class = $this->container->getParameterBag()->resolveValue($class); + if ($deprecated = $definition->isDeprecated()) { + $prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) { + return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line); + }); + } + + $e = null; + try { $reflector = new \ReflectionClass($class); - } catch (\ReflectionException $e) { + } catch (\Exception $e) { + } catch (\Throwable $e) { + } + + if ($deprecated) { + restore_error_handler(); + } + + if (null !== $e) { + if (!$e instanceof \ReflectionException) { + throw $e; + } $reflector = false; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 9cc7d1af71813..5d15ecc0bb76f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -442,6 +442,17 @@ public function testIgnoreServiceWithClassNotExisting() $this->assertTrue($container->hasDefinition('bar')); } + public function testProcessDoesNotTriggerDeprecations() + { + $container = new ContainerBuilder(); + $container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true); + $container->register('foo', __NAMESPACE__.'\Foo'); + $container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true); + + $pass = new AutowirePass(); + $pass->process($container); + } + public function testEmptyStringIsKept() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/DeprecatedClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/DeprecatedClass.php new file mode 100644 index 0000000000000..33f37a0304f92 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/DeprecatedClass.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Fixtures; + +@trigger_error('deprecated', E_USER_DEPRECATED); + +class DeprecatedClass +{ +}