[DI] Avoid private call to Container::has()
This commit is contained in:
parent
b0b7a36354
commit
56892819e3
@ -1191,9 +1191,17 @@ EOF;
|
||||
|
||||
$conditions = array();
|
||||
foreach ($services as $service) {
|
||||
if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$conditions[] = sprintf("\$this->has('%s')", $service);
|
||||
}
|
||||
|
||||
if (!$conditions) {
|
||||
return $code;
|
||||
}
|
||||
|
||||
// re-indent the wrapped code
|
||||
$code = implode("\n", array_map(function ($line) { return $line ? ' '.$line : $line; }, explode("\n", $code)));
|
||||
|
||||
|
@ -15,6 +15,7 @@ use DummyProxyDumper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
@ -406,4 +407,21 @@ class PhpDumperTest extends TestCase
|
||||
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_frozen.php', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testPrivateWithIgnoreOnInvalidReference()
|
||||
{
|
||||
require_once self::$fixturesPath.'/includes/classes.php';
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('not_invalid', 'BazClass')
|
||||
->setPublic(false);
|
||||
$container->register('bar', 'BarClass')
|
||||
->addMethodCall('setBaz', array(new Reference('not_invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference')));
|
||||
|
||||
$container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference();
|
||||
$this->assertInstanceOf('BazClass', $container->get('bar')->getBaz());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user