Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
[DI] Prevent AutowirePass from triggering irrelevant deprecations
  • Loading branch information
chalasr committed Apr 5, 2017
commit 77927f4b3322cd077fd002d239fe191e5f2ba166
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 <[email protected]>
*
* 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
{
}