8000 [DI] Prevent AutowirePass from triggering irrelevant deprecations by chalasr · Pull Request #22282 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Prevent AutowirePass from triggering irrelevant deprecations #22282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}
0