Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8985dd8

Browse filesBrowse files
committed
[DependencyInjection] Implement lazy edges in dependency graph
1 parent 6b6fe6b commit 8985dd8
Copy full SHA for 8985dd8

File tree

Expand file treeCollapse file tree

4 files changed

+30
-10
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+30
-10
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
1415
use Symfony\Component\DependencyInjection\Definition;
1516
use Symfony\Component\DependencyInjection\Reference;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -91,19 +92,25 @@ public function process(ContainerBuilder $container)
9192
* Processes service definitions for arguments to find relationships for the service graph.
9293
*
9394
* @param array $arguments An array of Reference or Definition objects relating to service definitions
95+
* @param boolean $lazy Whether the references nested in the arguments should be considered lazy or not
9496
*/
95-
private function processArguments(array $arguments)
97+
private function processArguments(array $arguments, $lazy = false)
9698
{
9799
foreach ($arguments as $argument) {
98100
if (is_array($argument)) {
99-
$this->processArguments($argument);
101+
$this->processArguments($argument, $lazy);
102+
} elseif ($argument instanceof ArgumentInterface) {
103+
$this->processArguments($argument->getValues(), true);
100104
} elseif ($argument instanceof Reference) {
105+
$targetDefinition = $this->getDefinition((string) $argument);
106+
101107
$this->graph->connect(
102108
$this->currentId,
103109
$this->currentDefinition,
104110
$this->getDefinitionId((string) $argument),
105-
$this->getDefinition((string) $argument),
106-
$argument
111+
$targetDefinition,
112+
$argument,
113+
$lazy ?: ($targetDefinition && $targetDefinition->isLazy())
107114
);
108115
} elseif ($argument instanceof Definition) {
109116
$this->processArguments($argument->getArguments());

‎src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ private function checkOutEdges(array $edges)
6060
$id = $node->getId();
6161

6262
if (empty($this->checkedNodes[$id])) {
63-
64-
// don't check circular dependencies for lazy services
65-
if (!$node->getValue() || !$node->getValue()->isLazy()) {
63+
// Don't check circular references for lazy edges
64+
if (!$node->getValue() || !$edge->isLazy()) {
6665
$searchKey = array_search($id, $this->currentPath);
6766
$this->currentPath[] = $id;
6867

‎src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ public function clear()
8484
* @param string $destId
8585
* @param string $destValue
8686
* @param string $reference
87+
* @param boolean $lazy
8788
*/
88-
public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null)
89+
public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null, $lazy = false)
8990
{
9091
$sourceNode = $this->createNode($sourceId, $sourceValue);
9192
$destNode = $this->createNode($destId, $destValue);
92-
$edge = new ServiceReferenceGraphEdge($sourceNode, $destNode, $reference);
93+
$edge = new ServiceReferenceGraphEdge($sourceNode, $destNode, $reference, $lazy);
9394

9495
$sourceNode->addOutEdge($edge);
9596
$destNode->addInEdge($edge);

‎src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ class ServiceReferenceGraphEdge
2323
private $sourceNode;
2424
private $destNode;
2525
private $value;
26+
private $lazy;
2627

2728
/**
2829
* @param ServiceReferenceGraphNode $sourceNode
2930
* @param ServiceReferenceGraphNode $destNode
3031
* @param string $value
32+
* @param boolean $lazy
3133
*/
32-
public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceReferenceGraphNode $destNode, $value = null)
34+
public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceReferenceGraphNode $destNode, $value = null, $lazy = false)
3335
{
3436
$this->sourceNode = $sourceNode;
3537
$this->destNode = $destNode;
3638
$this->value = $value;
39+
$this->lazy = $lazy;
3740
}
3841

3942
/**
@@ -65,4 +68,14 @@ public function getDestNode()
6568
{
6669
return $this->destNode;
6770
}
71+
72+
/**
73+
* Returns true if the edge is lazy, meaning it's a dependency not requiring direct instanciation.
74+
*
75+
* @return bool
76+
*/
77+
public function isLazy()
78+
{
79+
return $this->lazy;
80+
}
6881
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.