Merge branch '3.4' into 4.1

* 3.4:
  [DI] Fix dumping expressions accessing single-use private services
This commit is contained in:
Nicolas Grekas 2018-12-02 11:06:14 +01:00
commit 7c79dc2806
13 changed files with 25 additions and 26 deletions

View File

@ -564,9 +564,7 @@ EOF;
if ($callable[0] instanceof Reference if ($callable[0] instanceof Reference
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0])) || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))
) { ) {
$callable[0] = $this->dumpValue($callable[0]); return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
return sprintf(' '.('$' === $callable[0][0] ? '%s' : '(%s)')."->%s(\$%s);\n", $callable[0], $callable[1], $variableName);
} }
$class = $this->dumpValue($callable[0]); $class = $this->dumpValue($callable[0]);
@ -1610,6 +1608,7 @@ EOF;
if ($definition->isShared()) { if ($definition->isShared()) {
$code = sprintf('$this->%s[\'%s\'] = %s', $definition->isPublic() ? 'services' : 'privates', $id, $code); $code = sprintf('$this->%s[\'%s\'] = %s', $definition->isPublic() ? 'services' : 'privates', $id, $code);
} }
$code = "($code)";
} elseif ($this->asFiles && !$this->isHotPath($definition)) { } elseif ($this->asFiles && !$this->isHotPath($definition)) {
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id)); $code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
if (!$definition->isShared()) { if (!$definition->isShared()) {

View File

@ -792,7 +792,7 @@ class PhpDumperTest extends TestCase
->setPublic(false); ->setPublic(false);
$container->register('public_foo', 'stdClass') $container->register('public_foo', 'stdClass')
->setPublic(true) ->setPublic(true)
->addArgument(new Expression('service("private_foo")')); ->addArgument(new Expression('service("private_foo").bar'));
$container->compile(); $container->compile();
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);

View File

@ -347,7 +347,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () { return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
yield 0 => ($this->services['foo'] ?? $this->load('getFooService.php')); 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)); }, 2));
[Container%s/getTaggedIteratorFooService.php] => <?php [Container%s/getTaggedIteratorFooService.php] => <?php

View File

@ -402,7 +402,7 @@ class ProjectServiceContainer extends Container
{ {
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () { return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
yield 0 => ($this->services['foo'] ?? $this->getFooService()); 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)); }, 2));
} }

View File

@ -114,7 +114,7 @@ class Symfony_DI_PhpDumper_Test_Almost_Circular_Public extends Container
{ {
$this->services['bar3'] = $instance = new \BarCircular(); $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); $instance->addFoobar($a, $a);

View File

@ -70,7 +70,7 @@ class ProjectServiceContainer extends Container
*/ */
protected function getBarService() 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() 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) public function getParameter($name)

View File

@ -402,7 +402,7 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container
{ {
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () { return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
yield 0 => ($this->services['foo'] ?? $this->getFooService()); 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)); }, 2));
} }

View File

@ -76,7 +76,7 @@ class ProjectServiceContainer extends Container
*/ */
protected function getBarServiceService() 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['foo_service'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('bar' => function () {
return ($this->services['bar_service'] ?? $this->getBarServiceService()); return ($this->services['bar_service'] ?? $this->getBarServiceService());
}, 'baz' => function (): \stdClass { }, '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 () { }, 'nil' => function () {
return NULL; return NULL;
})); }));
@ -133,7 +133,7 @@ class ProjectServiceContainer extends Container
protected function getTranslator1Service() 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_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() 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 () { $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; return $instance;
} }
@ -161,10 +161,10 @@ class ProjectServiceContainer extends Container
protected function getTranslator3Service() 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 () { $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, 'nl');
$instance->addResource('db', $a, 'en'); $instance->addResource('db', $a, 'en');

View File

@ -67,7 +67,7 @@ class ProjectServiceContainer extends Container
*/ */
protected function getBarServiceService() 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() 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())));
} }
} }

View File

@ -67,6 +67,6 @@ class ProjectServiceContainer extends Container
*/ */
protected function getPublicFooService() 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);
} }
} }

View File

@ -79,7 +79,7 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container
protected function getContainer_EnvVarProcessorsLocatorService() protected function getContainer_EnvVarProcessorsLocatorService()
{ {
return $this->services['container.env_var_processors_locator'] = new \Symfony\Component\DependencyInjection\ServiceLocator(array('rot13' => function () { 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()));
})); }));
} }

View File

@ -80,13 +80,13 @@ class ProjectServiceContainer extends Container
protected function getFooServiceService() 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->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 { }, '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 { }, '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 { }, '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)); })))->withContext('foo_service', $this));
} }
} }

View File

@ -107,7 +107,7 @@ class Symfony_DI_PhpDumper_Test_Uninitialized_Reference extends Container
{ {
$this->services['baz'] = $instance = new \stdClass(); $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; return $instance;
} }