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 77927f4

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

File tree

3 files changed

+49
-1
lines changed
Filter options

3 files changed

+49
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,28 @@ private function getReflectionClass($id, Definition $definition)
303303

304304
$class = $this->container->getParameterBag()->resolveValue($class);
305305

306+
if ($deprecated = $definition->isDeprecated()) {
307+
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
308+
return (E_USER_DEPRECATED === $level || !$prevErrorHandler) ? false : $prevErrorHandler($level, $message, $file, $line);
309+
});
310+
}
311+
312+
$e = null;
313+
306314
try {
307315
$reflector = new \ReflectionClass($class);
308-
} catch (\ReflectionException $e) {
316+
} catch (\Exception $e) {
317+
} catch (\Throwable $e) {
318+
}
319+
320+
if ($deprecated) {
321+
restore_error_handler();
322+
}
323+
324+
if (null !== $e) {
325+
if (!$e instanceof \ReflectionException) {
326+
throw $e;
327+
}
309328
$reflector = false;
310329
}
311330

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@ public function testIgnoreServiceWithClassNotExisting()
442442
$this->assertTrue($container->hasDefinition('bar'));
443443
}
444444

445+
public function testProcessDoesNotTriggerDeprecations()
446+
{
447+
$container = new ContainerBuilder();
448+
$container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true);
449+
$container->register('foo', __NAMESPACE__.'\Foo');
450+
$container->register('bar', __NAMESPACE__.'\Bar')->setAutowired(true);
451+
452+
$pass = new AutowirePass();
453+
$pass->process($container);
454+
}
455+
445456
public function testEmptyStringIsKept()
446457
{
447458
$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.