Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93c0b38

Browse filesBrowse files
[DI] Add missing deprecation when fetching private services from ContainerBuilder
1 parent b9fb27c commit 93c0b38
Copy full SHA for 93c0b38

15 files changed

+32
-12
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php
+2-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+8-9Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt
+2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
+2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_legacy_privates.php
+8Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_locator.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_frozen.php
+1Lines 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

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_private_in_expression.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getRemovedIds()
3939
'Psr\\Container\\ContainerInterface' => true,
4040
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
4141
'private_bar' => true,
42+
'private_foo' => true,
4243
);
4344
}
4445

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function getRemovedIds()
4343
return array(
4444
'Psr\\Container\\ContainerInterface' => true,
4545
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
46+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
4647
'service_locator.jmktfsv' => true,
4748
);
4849
}

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_uninitialized_ref.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_uninitialized_ref.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function getRemovedIds()
4141
'Psr\\Container\\ContainerInterface' => true,
4242
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
4343
'foo2' => true,
44+
'foo3' => true,
4445
);
4546
}
4647

‎src/Symfony/Component/HttpKernel/Controller/ContainerControllerResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ContainerControllerResolver.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function instantiateController($class)
9494
} catch (\TypeError $e) {
9595
}
9696

97-
if ($this->container instanceof Container && in_array($class, $this->container->getRemovedIds(), true)) {
97+
if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$class])) {
9898
throw new \LogicException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $class), 0, $e);
9999
}
100100

‎src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function testNonConstructController()
130130
$container->expects($this->atLeastOnce())
131131
->method('getRemovedIds')
132132
->with()
133-
->will($this->returnValue(array(ImpossibleConstructController::class)))
133+
->will($this->returnValue(array(ImpossibleConstructController::class => true)))
134134
;
135135

136136
$resolver = $this->createControllerResolver(null, $container);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.