Skip to content

Commit ee572b3

Browse files
committed
merged branch hidenorigoto/fix-di-phpdumper (PR symfony#5194)
Commits ------- 1a4a4ee [DependencyInjection] Fixed a frozen constructor of a container with no parameters 2a124bc [DependencyInjection] Added a test for a frozen constructor of a container with no parameters Discussion ---------- [DependencyInjection] Fix PHP Dumper for a constructor of a frozen container with no parameters Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: Todo: - License of the code: MIT --------------------------------------------------------------------------- by travisbot at 2012-08-06T16:51:20Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/2049206) (merged 1a4a4ee into 3d32a0b).
2 parents f604058 + 1a4a4ee commit ee572b3

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,13 @@ private function addFrozenConstructor()
689689
*/
690690
public function __construct()
691691
{
692-
\$this->parameters = \$this->getDefaultParameters();
692+
EOF;
693+
694+
if ($this->container->getParameterBag()->all()) {
695+
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
696+
}
697+
698+
$code .= <<<EOF
693699
694700
\$this->services =
695701
\$this->scopedServices =

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ public function testDump()
3737
new PhpDumper($container);
3838
}
3939

40+
public function testDumpFrozenContainerWithNoParameter()
41+
{
42+
$container = new ContainerBuilder();
43+
$container->register('foo', 'stdClass');
44+
45+
$container->compile();
46+
47+
$dumper = new PhpDumper($container);
48+
49+
$dumpedString = $dumper->dump();
50+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
51+
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
52+
}
53+
4054
public function testDumpOptimizationString()
4155
{
4256
$definition = new Definition();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
use Symfony\Component\DependencyInjection\Reference;
7+
use Symfony\Component\DependencyInjection\Parameter;
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+
/**
19+
* Constructor.
20+
*/
21+
public function __construct()
22+
{
23+
$this->services =
24+
$this->scopedServices =
25+
$this->scopeStacks = array();
26+
27+
$this->set('service_container', $this);
28+
29+
$this->scopes = array();
30+
$this->scopeChildren = array();
31+
}
32+
33+
/**
34+
* Gets the 'foo' service.
35+
*
36+
* This service is shared.
37+
* This method always returns the same instance of the service.
38+
*
39+
* @return stdClass A stdClass instance.
40+
*/
41+
protected function getFooService()
42+
{
43+
return $this->services['foo'] = new \stdClass();
44+
}
45+
}

0 commit comments

Comments
 (0)