8000 [DependencyInjection] add missing dumped private services list in a container frozen constructor. by hhamon · Pull Request #21782 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] add missing dumped private services list in a container frozen constructor. #21782

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 1 commit into from
Feb 28, 2017
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
[DependencyInjection] add missing dumped private services list in a c…
…ontainer frozen constructor.
  • Loading branch information
Hugo Hamon committed Feb 27, 2017
commit 838d9ca6c01b0054e0a7dc8872dcb253905b6a48
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ public function __construct()

$code .= "\n \$this->services = array();\n";
$code .= $this->addMethodMap();
$code .= $this->addPrivateServices();
$code .= $this->addAliases();

$code .= <<<'EOF'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,17 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
$dumper->setProxyDumper(new DummyProxyDumper());
$dumper->dump();
}

public function testDumpContainerBuilderWithFrozenConstructorIncludingPrivateServices()
{
$container = new ContainerBuilder();
$container->register('foo_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
$container->register('bar_service', 'stdClass')->setArguments(array(new Reference('baz_service')));
$container->register('baz_service', 'stdClass')->setPublic(false);
$container->compile();

$dumper = new PhpDumper($container);

$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_frozen.php', $dumper->dump());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;

/**
* ProjectServiceContainer.
*
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();

/**
* Constructor.
*/
public function __construct()
{
$this->services = array();
$this->methodMap = array(
'bar_service' => 'getBarServiceService',
'baz_service' => 'getBazServiceService',
'foo_service' => 'getFooServiceService',
);
$this->privates = array(
'baz_service' => true,
);

$this->aliases = array();
}

/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}

/**
* {@inheritdoc}
*/
public function isFrozen()
{
return true;
}

/**
* Gets the 'bar_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance
*/
protected function getBarServiceService()
{
return $this->services['bar_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
}

/**
* Gets the 'foo_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* @return \stdClass A stdClass instance
*/
protected function getFooServiceService()
{
return $this->services['foo_service'] = new \stdClass(${($_ = isset($this->services['baz_service']) ? $this->services['baz_service'] : $this->getBazServiceService()) && false ?: '_'});
}

/**
* Gets the 'baz_service' service.
*
* This service is shared.
* This method always returns the same instance of the service.
*
* This service is private.
* If you want to be able to request this service from the container directly,
* make it public, otherwise you might end up with broken code.
*
* @return \stdClass A stdClass instance
*/
protected function getBazServiceService()
{
return $this->services['baz_service'] = new \stdClass();
}
}
0