8000 bug #25244 [DI] Add missing deprecation when fetching private service… · symfony/symfony@9401afd · GitHub
[go: up one dir, main page]

Skip to content

Commit 9401afd

Browse files
committed
bug #25244 [DI] Add missing deprecation when fetching private services from ContainerBuilder (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Add missing deprecation when fetching private services from ContainerBuilder | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25242 | License | MIT | Doc PR | - Commits ------- 93c0b38 [DI] Add missing deprecation when fetching private services from ContainerBuilder
2 parents 41e6f8e + 93c0b38 commit 9401afd

15 files changed

+32
-12
lines changed

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $e
232232
}
233233
$container->registerExtension(new TwigExtension());
234234
$container->loadFromExtension('twig', array());
235+
$container->setAlias('test.twig.extension.debug.stopwatch', 'twig.extension.debug.stopwatch')->setPublic(true);
235236
$this->compileContainer($container);
236237

237-
$tokenParsers = $container->get('twig.extension.debug.stopwatch')->getTokenParsers();
238+
$tokenParsers = $container->get('test.twig.extension.debug.stopwatch')->getTokenParsers();
238239
$stopwatchIsAvailable = new \ReflectionProperty($tokenParsers[0], 'stopwatchIsAvailable');
239240
$stopwatchIsAvailable->setAccessible(true);
240241

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,8 @@ public function has($id)
556556
*/
557557
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
558558
{
559-
if ($this->isCompiled()) {
560-
$id = $this->normalizeId($id);
561-
562-
if (isset($this->definitions[$id]) && $this->definitions[$id]->isPrivate()) {
563-
@trigger_error(sprintf('Fetching the "%s" private service is deprecated and will fail in Symfony 4.0. Make the service public instead.', $id), E_USER_DEPRECATED);
564-
}
565-
if (isset($this->aliasDefinitions[$id]) && $this->aliasDefinitions[$id]->isPrivate()) {
566-
@trigger_error(sprintf('Fetching the "%s" private alias is deprecated and will fail in Symfony 4.0. Make the alias public instead.', $id), E_USER_DEPRECATED);
567-
}
559+
if ($this->isCompiled() && isset($this->removedIds[$id = $this->normalizeId($id)])) {
560+
@trigger_error(sprintf('Fetching the "%s" private service or alias is deprecated since Symfony 3.4 and will fail in 4.0. Make it public instead.', $id), E_USER_DEPRECATED);
568561
}
569562

570563
return $this->doGet($id, $invalidBehavior);
@@ -776,6 +769,12 @@ public function compile(/*$resolveEnvPlaceholders = false*/)
776769
}
777770

778771
parent::compile();
772+
773+
foreach ($this->definitions + $this->aliasDefinitions as $id => $definition) {
774+
if (!$definition->isPublic() || $definition->isPrivate()) {
775+
$this->removedIds[$id] = true;
776+
}
777+
}
779778
}
780779

781780
/**

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ public function testEnvInId()
733733
PsrContainerInterface::class => true,
734734
ContainerInterface::class => true,
735735
'baz_%env(BAR)%' => true,
736+
'bar_%env(BAR)%' => true,
736737
);
737738
$this->assertSame($expected, $container->getRemovedIds());
738739

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ return array(
99
'configurator_service_simple' => true,
1010
'decorated.pif-pouf' => true,
1111
'decorator_service.inner' => true,
12+
'factory_simple' => true,
1213
'inlined' => true,
1314
'new_factory' => true,
15+
'tagged_iterator_foo' => true,
1416
);
1517

1618
[Container%s/getBazService.php] => <?php

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public function getRemovedIds()
7070
'configurator_service_simple' => true,
7171
'decorated.pif-pouf' => true,
7272
'decorator_service.inner' => true,
73+
'factory_simple' => true,
7374
'inlined' => true,
7475
'new_factory' => true,
76+
'tagged_iterator_foo' => true,
7577
);
7678
}
7779

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function getRemovedIds()
4444
return array(
4545
'Psr\\Container\\ContainerInterface' => true,
4646
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
47+
'bar_%env(BAR)%' => true,
4748
'baz_%env(BAR)%' => true,
4849
);
4950
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function getRemovedIds()
5757
return array(
5858
'Psr\\Container\\ContainerInterface' => true,
5959
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
60+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3' => true,
6061
);
6162
}
6263

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_legacy_privates.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ public function getRemovedIds()
6060
return array(
6161
'Psr\\Container\\ContainerInterface' => true,
6262
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
63+
'decorated_private' => true,
64+
'decorated_private_alias' => true,
6365
'foo' => true,
66+
'private' => true,
67+
'private_alias' => true,
6468
'private_alias_decorator.inner' => true,
69+
'private_child' => true,
6570
'private_decorator.inner' => true,
71+
'private_not_inlined' => true,
72+
'private_not_removed' => true,
73+
'private_parent' => true,
6674
);
6775
}
6876

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function getRemovedIds()
4545
return array(
4646
'Psr\\Container\\ContainerInterface' => true,
4747
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
48+
'baz_service' => true,
4849
'translator.loader_1_locator' => true,
4950
'translator.loader_2_locator' => true,
5051
'translator.loader_3_locator' => true,

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getRemovedIds()
3939
return array(
4040
'Psr\\Container\\ContainerInterface' => true,
4141
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
42+
'baz_service' => true,
4243
);
4344
}
4445

0 commit comments

Comments
 (0)
0