Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 333fd36

Browse filesBrowse files
committed
[DI] Prevent AutowirePass from triggering irrelevant deprecations
1 parent 200b45e commit 333fd36
Copy full SHA for 333fd36

File tree

3 files changed

+43
-0
lines changed
Filter options

3 files changed

+43
-0
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ private function getReflectionClass($id, Definition $definition)
301301
return false;
302302
}
303303

304+
if ($deprecated = $definition->isDeprecated()) {
305+
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line, $context) use (&$prevErrorHandler) {
306+
if (E_USER_DEPRECATED === $level) {
307+
return false;
308+
}
309+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line, $context) : false;
310+
});
311+
}
312+
304313
$class = $this->container->getParameterBag()->resolveValue($class);
305314

306315
try {
@@ -309,6 +318,10 @@ private function getReflectionClass($id, Definition $definition)
309318
$reflector = false;
310319
}
311320

321+
if ($deprecated) {
322+
restore_error_handler();
323+
}
324+
312325
return $this->reflectionClasses[$id] = $reflector;
313326
}
314327
}

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass;
1819

1920
/**
2021
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -442,6 +443,17 @@ public function testIgnoreServiceWithClassNotExisting()
442443
$this->assertTrue($container->hasDefinition('bar'));
443444
}
444445

446+
public function testIgnoreDeprecatedServices()
447+
{
448+
$container = new ContainerBuilder();
449+
$container->register('deprecated', DeprecatedClass::class)->setDeprecated(true);
450+
$container->register('foo', __NAMESPACE__.'\Foo');
451+
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
452+
453+
$pass = new AutowirePass();
454+
$pass->process($container);
455+
}
456+
445457
public function testEmptyStringIsKept()
446458
{
447459
$container = new ContainerBuilder();
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
@trigger_error('deprecated', E_USER_DEPRECATED);
15+
16+
class DeprecatedClass
17+
{
18+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.