Skip to content

[DI] configure inlined services before injecting when dumping the container #28385

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

Closed
wants to merge 1 commit into from
Closed
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
402 changes: 140 additions & 262 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,14 @@ public function testDeepServiceGraph()
$dumper = new PhpDumper($container);
$dumper->dump();

$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump());
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Deep_Graph')));

require self::$fixturesPath.'/php/services_deep_graph.php';

$container = new \Symfony_DI_PhpDumper_Test_Deep_Graph();

$this->assertInstanceOf(FooForDeepGraph::class, $container->get('foo'));
$this->assertEquals((object) array('p2' => (object) array('p3' => (object) array())), $container->get('foo')->bClone);
}

public function testHotPathOptimizations()
Expand Down Expand Up @@ -1041,3 +1048,14 @@ public static function getProvidedTypes()
return array('rot13' => 'string');
}
}

class FooForDeepGraph
{
public $bClone;

public function __construct(\stdClass $a, \stdClass $b)
{
// clone to verify that $b has been fully initialized before
$this->bClone = clone $b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function getRemovedIds()
protected function getBarService()
{
$a = new \stdClass();

$a->add($this);

return $this->services['bar'] = new \stdClass($a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
$this->services['configured_service'] = $instance = new \stdClass();

$a = new \ConfClass();

$a->setFoo(($this->services['baz'] ?? $this->load('getBazService.php')));

$a->configureStdClass($instance);
Expand Down Expand Up @@ -294,6 +295,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
// Returns the public 'new_factory_service' shared service.

$a = new \FactoryClass();

$a->foo = 'bar';

$this->services['new_factory_service'] = $instance = $a->getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected function getConfiguredServiceService()
$this->services['configured_service'] = $instance = new \stdClass();

$a = new \ConfClass();

$a->setFoo(($this->services['baz'] ?? $this->getBazService()));

$a->configureStdClass($instance);
Expand Down Expand Up @@ -365,6 +366,7 @@ protected function getMethodCall1Service()
protected function getNewFactoryServiceService()
{
$a = new \FactoryClass();

$a->foo = 'bar';

$this->services['new_factory_service'] = $instance = $a->getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected function getConnectionService()
$this->services['connection'] = $instance = new \stdClass($a, $b);

$a->subscriber = ($this->services['subscriber'] ?? $this->getSubscriberService());

$b->logger = ($this->services['logger'] ?? $this->getLoggerService());

return $instance;
Expand All @@ -139,17 +140,19 @@ protected function getConnection2Service()
{
$a = new \stdClass();

$b = new \stdClass();
$c = new \stdClass();

$this->services['connection2'] = $instance = new \stdClass($a, $b);
$this->services['connection2'] = $instance = new \stdClass($a, $c);

$c = ($this->services['manager2'] ?? $this->getManager2Service());
$b = ($this->services['manager2'] ?? $this->getManager2Service());

$a->subscriber2 = new \stdClass($b);

$d = new \stdClass($instance);

$a->subscriber2 = new \stdClass($c);
$d->handler2 = new \stdClass($c);
$b->logger2 = $d;
$d->handler2 = new \stdClass($b);

$c->logger2 = $d;

return $instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected function getConnection2Service()
$c = new \stdClass($instance);

$c->handler2 = new \stdClass(($this->services['manager2'] ?? $this->getManager2Service()));

$b->logger2 = $c;

return $instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @final since Symfony 3.3
*/
class ProjectServiceContainer extends Container
class Symfony_DI_PhpDumper_Test_Deep_Graph extends Container
{
private $parameters;
private $targetDirs = array();
Expand Down Expand Up @@ -62,21 +62,21 @@ public function getRemovedIds()
/**
* Gets the public 'bar' shared service.
*
* @return \c5
* @return \stdClass
*/
protected function getBarService()
{
$this->services['bar'] = $instance = new \c5();
$this->services['bar'] = $instance = new \stdClass();

$instance->p5 = new \c6(($this->services['foo'] ?? $this->getFooService()));
$instance->p5 = new \stdClass(($this->services['foo'] ?? $this->getFooService()));

return $instance;
}

/**
* Gets the public 'foo' shared service.
*
* @return \c1
* @return \Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph
*/
protected function getFooService()
{
Expand All @@ -86,15 +86,13 @@ protected function getFooService()
return $this->services['foo'];
}

$b = new \c2();
$b = new \stdClass();

$this->services['foo'] = $instance = new \c1($a, $b);
$c = new \stdClass();

$c = new \c3();

$c->p3 = new \c4();
$c->p3 = new \stdClass();
$b->p2 = $c;

return $instance;
return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph($a, $b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected function getConfiguredServiceService()
$this->services['configured_service'] = $instance = new \stdClass();

$a = new \ConfClass();

$a->setFoo(($this->services['baz'] ?? $this->getBazService()));

$a->configureStdClass($instance);
Expand Down Expand Up @@ -365,6 +366,7 @@ protected function getMethodCall1Service()
protected function getNewFactoryServiceService()
{
$a = new \FactoryClass();

$a->foo = 'bar';

$this->services['new_factory_service'] = $instance = $a->getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ protected function getC1Service()
*/
protected function getC2Service()
{
include_once $this->targetDirs[1].'/includes/HotPath/C3.php';
include_once $this->targetDirs[1].'/includes/HotPath/C2.php';
include_once $this->targetDirs[1].'/includes/HotPath/C3.php';

return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@

services:
foo:
class: c1
class: Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph
public: true
arguments:
- '@bar'
- !service
class: c2
class: stdClass
properties:
p2: !service
class: c3
class: stdClass
properties:
p3: !service
class: c4
class: stdClass

bar:
class: c5
class: stdClass
public: true
properties:
p5: !service
class: c6
class: stdClass
arguments: ['@foo']