8000 [DependencyInjection] Fix PHP Dumper for a constructor of a frozen container with no parameters by hidenorigoto · Pull Request #5194 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Fix PHP Dumper for a constructor of a frozen container with no parameters #5194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,13 @@ private function addFrozenConstructor()
*/
public function __construct()
{
\$this->parameters = \$this->getDefaultParameters();
EOF;

if ($this->container->getParameterBag()->all()) {
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
}

$code .= <<<EOF

\$this->services =
\$this->scopedServices =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ public function testDump()
new PhpDumper($container);
}

public function testDumpFrozenContainerWithNoParameter()
{
$container = new ContainerBuilder();
$container->register('foo', 'stdClass');

$container->compile();

$dumper = new PhpDumper($container);

$dumpedString = $dumper->dump();
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
}

public function testDumpOptimizationString()
{
$definition = new Definition();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
* ProjectServiceContainer
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
/**
* Constructor.
*/
public function __construct()
{
$this->services =
$this->scopedServices =
$this->scopeStacks = array();

$this->set('service_container', $this);

$this->scopes = array();
$this->scopeChildren = array();
}

/**
* Gets the 'foo' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return stdClass A stdClass instance.
*/
protected function getFooService()
{
return $this->services['foo'] = new \stdClass();
}
}
0