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

Skip to content

Commit 943f9b6

Browse files
author
Hugo Hamon
committed
[DependencyInjection] add missing dumped private services list in a container frozen constructor.
1 parent 346eacd commit 943f9b6

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Config\FileLocator;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
19+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
1920
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2021
use Symfony\Component\DependencyInjection\Reference;
2122
use Symfony\Component\DependencyInjection\Definition;
@@ -392,4 +393,19 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
392393
$dumper->setProxyDumper(new DummyProxyDumper());
393394
$dumper->dump();
394395
}
396+
397+
public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices()
398+
{
399+
$container = new ContainerBuilder();
400+
$container->register('foo_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
401+
$container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
402+
$container->register('baz_service', 'stdClass')->setPublic(false);
403+
$container->compile();
404+
405+
$dumper = new PhpDumper($container);
406+
407+
file_put_contents('/tmp/container27.php', $dumper->dump());
408+
409+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services27.php', $dumper->dump());
410+
}
395411
}
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)