Skip to content

[FrameworkBundle] acces public-deprecated services via the private container to remove false-positive deprecations #39361

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
Dec 8, 2020
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 @@ -22,6 +22,13 @@
*/
class TestServiceContainerWeakRefPass implements CompilerPassInterface
{
private $privateTagName;

public function __construct(string $privateTagName = 'container.private')
{
$this->privateTagName = $privateTagName;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('test.private_services_locator')) {
Expand All @@ -33,7 +40,7 @@ public function process(ContainerBuilder $container)
$hasErrors = method_exists(Definition::class, 'hasErrors') ? 'hasErrors' : 'getErrors';

foreach ($definitions as $id => $definition) {
if ($id && '.' !== $id[0] && (!$definition->isPublic() || $definition->isPrivate()) && !$definition->$hasErrors() && !$definition->isAbstract()) {
if ($id && '.' !== $id[0] && (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) && !$definition->$hasErrors() && !$definition->isAbstract()) {
$privateServices[$id] = new Reference($id, ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public function testProcess()
->setPublic(true)
->addArgument(new Reference('Test\private_used_shared_service'))
->addArgument(new Reference('Test\private_used_non_shared_service'))
->addArgument(new Reference('Test\soon_private_service'))
;

$container->register('Test\soon_private_service')
->setPublic(true)
->addTag('container.private', ['package' => 'foo/bar', 'version' => '1.42'])
;

$container->register('Test\private_used_shared_service');
Expand All @@ -48,6 +54,7 @@ public function testProcess()
$expected = [
'Test\private_used_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_shared_service')),
'Test\private_used_non_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_non_shared_service')),
'Test\soon_private_service' => new ServiceClosureArgument(new Reference('.container.private.Test\soon_private_service')),
'Psr\Container\ContainerInterface' => new ServiceClosureArgument(new Reference('service_container')),
'Symfony\Component\DependencyInjection\ContainerInterface' => new ServiceClosureArgument(new Reference('service_container')),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class AddConsoleCommandPass implements CompilerPassInterface
private $commandLoaderServiceId;
private $commandTag;
private $noPreloadTag;
private $privateTagName;

public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload')
public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private')
{
$this->commandLoaderServiceId = $commandLoaderServiceId;
$this->commandTag = $commandTag;
$this->noPreloadTag = $noPreloadTag;
$this->privateTagName = $privateTagName;
}

public function process(ContainerBuilder $container)
Expand Down Expand Up @@ -62,7 +64,7 @@ public function process(ContainerBuilder $container)
}

if (null === $commandName) {
if (!$definition->isPublic() || $definition->isPrivate()) {
if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) {
$commandId = 'console.command.public_alias.'.$id;
$container->setAlias($commandId, $id)->setPublic(true);
$id = $commandId;
Expand Down