Merge branch '3.4' into 4.1
* 3.4: [DI] Fix dumping expressions accessing single-use private services
This commit is contained in:
commit
7c79dc2806
@ -564,9 +564,7 @@ EOF;
|
||||
if ($callable[0] instanceof Reference
|
||||
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))
|
||||
) {
|
||||
$callable[0] = $this->dumpValue($callable[0]);
|
||||
|
||||
return sprintf(' '.('$' === $callable[0][0] ? '%s' : '(%s)')."->%s(\$%s);\n", $callable[0], $callable[1], $variableName);
|
||||
return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
|
||||
}
|
||||
|
||||
$class = $this->dumpValue($callable[0]);
|
||||
@ -1610,6 +1608,7 @@ EOF;
|
||||
if ($definition->isShared()) {
|
||||
$code = sprintf('$this->%s[\'%s\'] = %s', $definition->isPublic() ? 'services' : 'privates', $id, $code);
|
||||
}
|
||||
$code = "($code)";
|
||||
} elseif ($this->asFiles && !$this->isHotPath($definition)) {
|
||||
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
|
||||
if (!$definition->isShared()) {
|
||||
|
@ -792,7 +792,7 @@ class PhpDumperTest extends TestCase
|
||||
->setPublic(false);
|
||||
$container->register('public_foo', 'stdClass')
|
||||
->setPublic(true)
|
||||
->addArgument(new Expression('service("private_foo")'));
|
||||
->addArgument(new Expression('service("private_foo").bar'));
|
||||
|
||||
$container->compile();
|
||||
$dumper = new PhpDumper($container);
|
||||
|
@ -347,7 +347,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
||||
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
|
||||
yield 0 => ($this->services['foo'] ?? $this->load('getFooService.php'));
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? ($this->privates['tagged_iterator_foo'] = new \Bar()));
|
||||
}, 2));
|
||||
|
||||
[Container%s/getTaggedIteratorFooService.php] => <?php
|
||||
|
@ -402,7 +402,7 @@ class ProjectServiceContainer extends Container
|
||||
{
|
||||
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
|
||||
yield 0 => ($this->services['foo'] ?? $this->getFooService());
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? ($this->privates['tagged_iterator_foo'] = new \Bar()));
|
||||
}, 2));
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ class Symfony_DI_PhpDumper_Test_Almost_Circular_Public extends Container
|
||||
{
|
||||
$this->services['bar3'] = $instance = new \BarCircular();
|
||||
|
||||
$a = ($this->services['foobar3'] ?? $this->services['foobar3'] = new \FoobarCircular());
|
||||
$a = ($this->services['foobar3'] ?? ($this->services['foobar3'] = new \FoobarCircular()));
|
||||
|
||||
$instance->addFoobar($a, $a);
|
||||
|
||||
|
@ -70,7 +70,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getBarService()
|
||||
{
|
||||
return $this->services['bar'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? $this->privates['bar_%env(BAR)%'] = new \stdClass()));
|
||||
return $this->services['bar'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? ($this->privates['bar_%env(BAR)%'] = new \stdClass())));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +80,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getFooService()
|
||||
{
|
||||
return $this->services['foo'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? $this->privates['bar_%env(BAR)%'] = new \stdClass()), array('baz_'.$this->getEnv('string:BAR') => new \stdClass()));
|
||||
return $this->services['foo'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? ($this->privates['bar_%env(BAR)%'] = new \stdClass())), array('baz_'.$this->getEnv('string:BAR') => new \stdClass()));
|
||||
}
|
||||
|
||||
public function getParameter($name)
|
||||
|
@ -402,7 +402,7 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container
|
||||
{
|
||||
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
|
||||
yield 0 => ($this->services['foo'] ?? $this->getFooService());
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
|
||||
yield 1 => ($this->privates['tagged_iterator_foo'] ?? ($this->privates['tagged_iterator_foo'] = new \Bar()));
|
||||
}, 2));
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getBarServiceService()
|
||||
{
|
||||
return $this->services['bar_service'] = new \stdClass(($this->privates['baz_service'] ?? $this->privates['baz_service'] = new \stdClass()));
|
||||
return $this->services['bar_service'] = new \stdClass(($this->privates['baz_service'] ?? ($this->privates['baz_service'] = new \stdClass())));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +89,7 @@ class ProjectServiceContainer extends Container
|
||||
return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('bar' => function () {
|
||||
return ($this->services['bar_service'] ?? $this->getBarServiceService());
|
||||
}, 'baz' => function (): \stdClass {
|
||||
return ($this->privates['baz_service'] ?? $this->privates['baz_service'] = new \stdClass());
|
||||
return ($this->privates['baz_service'] ?? ($this->privates['baz_service'] = new \stdClass()));
|
||||
}, 'nil' => function () {
|
||||
return NULL;
|
||||
}));
|
||||
@ -133,7 +133,7 @@ class ProjectServiceContainer extends Container
|
||||
protected function getTranslator1Service()
|
||||
{
|
||||
return $this->services['translator_1'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_1' => function () {
|
||||
return ($this->services['translator.loader_1'] ?? $this->services['translator.loader_1'] = new \stdClass());
|
||||
return ($this->services['translator.loader_1'] ?? ($this->services['translator.loader_1'] = new \stdClass()));
|
||||
})));
|
||||
}
|
||||
|
||||
@ -145,10 +145,10 @@ class ProjectServiceContainer extends Container
|
||||
protected function getTranslator2Service()
|
||||
{
|
||||
$this->services['translator_2'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_2' => function () {
|
||||
return ($this->services['translator.loader_2'] ?? $this->services['translator.loader_2'] = new \stdClass());
|
||||
return ($this->services['translator.loader_2'] ?? ($this->services['translator.loader_2'] = new \stdClass()));
|
||||
})));
|
||||
|
||||
$instance->addResource('db', ($this->services['translator.loader_2'] ?? $this->services['translator.loader_2'] = new \stdClass()), 'nl');
|
||||
$instance->addResource('db', ($this->services['translator.loader_2'] ?? ($this->services['translator.loader_2'] = new \stdClass())), 'nl');
|
||||
|
||||
return $instance;
|
||||
}
|
||||
@ -161,10 +161,10 @@ class ProjectServiceContainer extends Container
|
||||
protected function getTranslator3Service()
|
||||
{
|
||||
$this->services['translator_3'] = $instance = new \Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator(new \Symfony\Component\DependencyInjection\ServiceLocator(array('translator.loader_3' => function () {
|
||||
return ($this->services['translator.loader_3'] ?? $this->services['translator.loader_3'] = new \stdClass());
|
||||
return ($this->services['translator.loader_3'] ?? ($this->services['translator.loader_3'] = new \stdClass()));
|
||||
})));
|
||||
|
||||
$a = ($this->services['translator.loader_3'] ?? $this->services['translator.loader_3'] = new \stdClass());
|
||||
$a = ($this->services['translator.loader_3'] ?? ($this->services['translator.loader_3'] = new \stdClass()));
|
||||
|
||||
$instance->addResource('db', $a, 'nl');
|
||||
$instance->addResource('db', $a, 'en');
|
||||
|
@ -67,7 +67,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getBarServiceService()
|
||||
{
|
||||
return $this->services['bar_service'] = new \stdClass(($this->privates['baz_service'] ?? $this->privates['baz_service'] = new \stdClass()));
|
||||
return $this->services['bar_service'] = new \stdClass(($this->privates['baz_service'] ?? ($this->privates['baz_service'] = new \stdClass())));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +77,6 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getFooServiceService()
|
||||
{
|
||||
return $this->services['foo_service'] = new \stdClass(($this->privates['baz_service'] ?? $this->privates['baz_service'] = new \stdClass()));
|
||||
return $this->services['foo_service'] = new \stdClass(($this->privates['baz_service'] ?? ($this->privates['baz_service'] = new \stdClass())));
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,6 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getPublicFooService()
|
||||
{
|
||||
return $this->services['public_foo'] = new \stdClass(($this->privates['private_foo'] ?? $this->privates['private_foo'] = new \stdClass()));
|
||||
return $this->services['public_foo'] = new \stdClass(($this->privates['private_foo'] ?? ($this->privates['private_foo'] = new \stdClass()))->bar);
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container
|
||||
protected function getContainer_EnvVarProcessorsLocatorService()
|
||||
{
|
||||
return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('rot13' => function () {
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] ?? $this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor());
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] ?? ($this->services['Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\Rot13EnvVarProcessor()));
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ class ProjectServiceContainer extends Container
|
||||
protected function getFooServiceService()
|
||||
{
|
||||
return $this->services['foo_service'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber((new \Symfony\Component\DependencyInjection\ServiceLocator(array('Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => function (): ?\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition {
|
||||
return ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] ?? $this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition());
|
||||
return ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] ?? ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition()));
|
||||
}, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber' => function (): \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber {
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] ?? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber());
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] ?? ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber()));
|
||||
}, 'bar' => function (): \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition {
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] ?? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber());
|
||||
return ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] ?? ($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber()));
|
||||
}, 'baz' => function (): ?\Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition {
|
||||
return ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] ?? $this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition());
|
||||
return ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] ?? ($this->privates['Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition()));
|
||||
})))->withContext('foo_service', $this));
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ class Symfony_DI_PhpDumper_Test_Uninitialized_Reference extends Container
|
||||
{
|
||||
$this->services['baz'] = $instance = new \stdClass();
|
||||
|
||||
$instance->foo3 = ($this->privates['foo3'] ?? $this->privates['foo3'] = new \stdClass());
|
||||
$instance->foo3 = ($this->privates['foo3'] ?? ($this->privates['foo3'] = new \stdClass()));
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
Reference in New Issue
Block a user