8000 bug #21782 [DependencyInjection] add missing dumped private services … · symfony/symfony@b69ca56 · GitHub
[go: up one dir, main page]

Skip to content

Commit b69ca56

Browse files
bug #21782 [DependencyInjection] add missing dumped private services list in a container frozen constructor. (hhamon)
This PR was merged into the 3.2 branch. Discussion ---------- [DependencyInjection] add missing dumped private services list in a container frozen constructor. | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- 838d9ca [DependencyInjection] add missing dumped private services list in a container frozen constructor.
2 parents fcde9e6 + 838d9ca commit b69ca56

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ public function __construct()
855855

856856
$code .= "\n \$this->services = array();\n";
857857
$code .= $this->addMethodMap();
858+
$code .= $this->addPrivateServices();
858859
$code .= $this->addAliases();
859860

860861
$code .= <<<'EOF'

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,17 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
389389
$dumper->setProxyDumper(new DummyProxyDumper());
390390
$dumper->dump();
391391
}
392+
393+
public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices()
394+
{
395+
$container = new ContainerBuilder();
396+
$container->register('foo_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
397+
$container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
398+
$container->register('baz_service', 'stdClass')->setPublic(false);
399+
$container->compile();
400+
401+
$dumper = new PhpDumper($container);
402+
403+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_frozen.php', $dumper->dump());
404+
}
392405
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
6+
use Symfony\Component\DependencyInjection\Exception\LogicException;
7+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
8+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
9+
10+
/**
11+
* ProjectServiceContainer.
12+
*
13+
* This class has been auto-generated
14+
* by the Symfony Dependency Injection Component.
15+
*/
16+
class ProjectServiceContainer extends Container
17+
{
18+
private $parameters;
19+
private $targetDirs = array();
20+
21+
/**
22+
* Constructor.
23+
*/
24+
public function __construct()
25+
{
26+
$this->services = array();
27+
$this->methodMap = array(
28+
'bar_service' => 'getBarServiceService',
29+
'baz_service' => 'getBazServiceService',
30+
'foo_service' => 'getFooServiceService',
31+
);
32+
$this->privates = array(
33+
'baz_service' => true,
34+
);
35+
36+
$this->aliases = array();
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function compile()
43+
{
44+
throw new LogicException('You cannot compile a dumped frozen container.');
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function isFrozen()
51+
{
52+
return true;
53+
}
54+
55+
/**
56+
* Gets the 'bar_service' service.
57+
*
58+
* This service is shared.
59+
* This method always returns the same instance of the service.
60+
*
61+
* @return \stdClass A stdClass instance
62+
*/
63+
protected function getBarServiceService()
64+
{
65+
return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
66+
}
67+
68+
/**
69+
* Gets the 'foo_service' service.
70+
*
71+
* This service is shared.
72+
* This method always returns the same instance of the service.
73+
*
74+
* @return \stdClass A stdClass instance
75+
*/
76+
protected function getFooServiceService()
77+
{
78+
return $this->services['foo_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
79+
}
80+
81+
/**
82+
* Gets the 'baz_service' service.
83+
*
84+
* This service is shared.
85+
* This method always returns the same instance of the service.
86+
*
87+
* This service is private.
88+
* If you want to be able to request this service from the container directly,
89+
* make it public, otherwise you might end up with broken code.
90+
*
91+
* @return \stdClass A stdClass instance
92+
*/
93+
protected function getBazServiceService()
94+
{
95+
return $this->services['baz_service'] = new \stdClass();
96+
}
97+
}

0 commit comments

Comments
 (0)
0