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

Skip to content

Fix decoration of private services #17649

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -48,16 +48,14 @@ public function process(ContainerBuilder $container)
// to be able to reference it in the new one
if ($container->hasAlias($inner)) {
$alias = $container->getAlias($inner);
$public = $alias->isPublic();
$container->setAlias($renamedId, new Alias((string) $alias, false));
} else {
$definition = $container->getDefinition($inner);
$public = $definition->isPublic();
$definition->setPublic(false);
$container->setDefinition($renamedId, $definition);
}

$container->setAlias($inner, new Alias($id, $public));
$container->setAlias($inner, new Alias($id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testProcessWithoutAlias()
$this->process($container);

$this->assertEquals('foo.extended', $container->getAlias('foo'));
$this->assertFalse($container->getAlias('foo')->isPublic());
$this->assertTrue($container->getAlias('foo')->isPublic());

$this->assertEquals('bar.extended', $container->getAlias('bar'));
$this->assertTrue($container->getAlias('bar')->isPublic());
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testProcessWithAlias()
$this->process($container);

$this->assertEquals('foo.extended', $container->getAlias('foo.alias'));
$this->assertFalse($container->getAlias('foo.alias')->isPublic());
$this->assertTrue($container->getAlias('foo.alias')->isPublic());

$this->assertEquals('foo', $container->getAlias('foo.extended.inner'));
$this->assertFalse($container->getAlias('foo.extended.inner')->isPublic());
Expand Down Expand Up @@ -108,7 +108,7 @@ public function testProcessWithPriority()
$this->process($container);

$this->assertEquals('bar', $container->getAlias('foo'));
$this->assertFalse($container->getAlias('foo')->isPublic());
$this->assertTrue($container->getAlias('foo')->isPublic());

$this->assertSame($fooDefinition, $container->getDefinition('baz.inner'));
$this->assertFalse($container->getDefinition('baz.inner')->isPublic());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

/**
* This class tests the integration of the different compiler passes.
Expand Down Expand Up @@ -113,4 +114,24 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe
$this->assertFalse($container->hasDefinition('b'));
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
}

public function testDecoratePrivateServiceDontThrowException()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);

$foo = $container->register('foo', '\stdClass');
$foo->setPublic(false);

$bar = $container->register('bar', '\stdClass');
$bar->setDecoratedService('foo');

$container->compile();

try {
$container->get('foo');
} catch (InvalidArgumentException $e) {
$this->fail('The service foo should exists, but it doesn\'t.');
}
}
}