[DI] Turn private defs to non-public ones before removing passes
This commit is contained in:
parent
b43bdf398d
commit
e5d0934b87
@ -71,6 +71,12 @@ class PassConfig
|
|||||||
new CheckArgumentsValidityPass(false),
|
new CheckArgumentsValidityPass(false),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->beforeRemovingPasses = array(
|
||||||
|
-100 => array(
|
||||||
|
new ResolvePrivatesPass(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
$this->removingPasses = array(array(
|
$this->removingPasses = array(array(
|
||||||
new RemovePrivateAliasesPass(),
|
new RemovePrivateAliasesPass(),
|
||||||
new ReplaceAliasByActualDefinitionPass(),
|
new ReplaceAliasByActualDefinitionPass(),
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
|
use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -26,28 +25,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|||||||
*/
|
*/
|
||||||
class ResolveChildDefinitionsPass extends AbstractRecursivePass
|
class ResolveChildDefinitionsPass extends AbstractRecursivePass
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function process(ContainerBuilder $container)
|
|
||||||
{
|
|
||||||
parent::process($container);
|
|
||||||
|
|
||||||
foreach ($container->getDefinitions() as $definition) {
|
|
||||||
if ($definition->isPrivate()) {
|
|
||||||
$definition->setPublic(false);
|
|
||||||
$definition->setPrivate(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($container->getAliases() as $alias) {
|
|
||||||
if ($alias->isPrivate()) {
|
|
||||||
$alias->setPublic(false);
|
|
||||||
$alias->setPrivate(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function processValue($value, $isRoot = false)
|
protected function processValue($value, $isRoot = false)
|
||||||
{
|
{
|
||||||
if (!$value instanceof Definition) {
|
if (!$value instanceof Definition) {
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
<?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\Compiler;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
*/
|
||||||
|
class ResolvePrivatesPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
foreach ($container->getDefinitions() as $id => $definition) {
|
||||||
|
if ($definition->isPrivate()) {
|
||||||
|
$definition->setPublic(false);
|
||||||
|
$definition->setPrivate(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($container->getAliases() as $id => $alias) {
|
||||||
|
if ($alias->isPrivate()) {
|
||||||
|
$alias->setPublic(false);
|
||||||
|
$alias->setPrivate(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -397,26 +397,6 @@ class ResolveChildDefinitionsPassTest extends TestCase
|
|||||||
$this->assertFalse($container->getDefinition('child1')->isAutoconfigured());
|
$this->assertFalse($container->getDefinition('child1')->isAutoconfigured());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPrivateHasHigherPrecedenceThanPublic()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
|
|
||||||
$container->register('foo', 'stdClass')
|
|
||||||
->setPublic(true)
|
|
||||||
->setPrivate(true)
|
|
||||||
;
|
|
||||||
|
|
||||||
$container->setAlias('bar', 'foo')
|
|
||||||
->setPublic(false)
|
|
||||||
->setPrivate(false)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
|
|
||||||
$this->assertFalse($container->getDefinition('foo')->isPublic());
|
|
||||||
$this->assertFalse($container->getAlias('bar')->isPublic());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
<?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\Compiler;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\ResolvePrivatesPass;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
class ResolvePrivatesPassTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPrivateHasHigherPrecedenceThanPublic()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container->register('foo', 'stdClass')
|
||||||
|
->setPublic(true)
|
||||||
|
->setPrivate(true)
|
||||||
|
;
|
||||||
|
|
||||||
|
$container->setAlias('bar', 'foo')
|
||||||
|
->setPublic(false)
|
||||||
|
->setPrivate(false)
|
||||||
|
;
|
||||||
|
|
||||||
|
(new ResolvePrivatesPass())->process($container);
|
||||||
|
|
||||||
|
$this->assertFalse($container->getDefinition('foo')->isPublic());
|
||||||
|
$this->assertFalse($container->getAlias('bar')->isPublic());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user