|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Compose\Visualization\Graph; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Compose\{ |
|
7
|
|
|
Definition\Name as ServiceName, |
|
8
|
|
|
Definition\Service\Constructor, |
|
9
|
|
|
Visualization\Node\Element |
|
10
|
|
|
}; |
|
11
|
|
|
use Innmind\Graphviz\{ |
|
12
|
|
|
Graph, |
|
13
|
|
|
Node, |
|
14
|
|
|
Graph\Name |
|
15
|
|
|
}; |
|
16
|
|
|
use Innmind\Colour\RGBA; |
|
17
|
|
|
use Innmind\Url\UrlInterface; |
|
18
|
|
|
use Innmind\Immutable\{ |
|
19
|
|
|
SetInterface, |
|
20
|
|
|
MapInterface |
|
21
|
|
|
}; |
|
22
|
|
|
|
|
23
|
|
|
final class Dependency implements Graph |
|
24
|
|
|
{ |
|
25
|
|
|
private $graph; |
|
26
|
|
|
|
|
27
|
14 |
|
public function __construct(ServiceName $dependency, MapInterface $services) |
|
28
|
|
|
{ |
|
29
|
|
|
if ( |
|
30
|
14 |
|
(string) $services->keyType() !== ServiceName::class || |
|
31
|
14 |
|
(string) $services->valueType() !== Constructor::class |
|
32
|
|
|
) { |
|
33
|
1 |
|
throw new \TypeError(sprintf( |
|
34
|
1 |
|
'Argument 2 must be of type MapInterface<%s, %s>', |
|
35
|
1 |
|
ServiceName::class, |
|
36
|
1 |
|
Constructor::class |
|
37
|
|
|
)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
14 |
|
$this->graph = $services->reduce( |
|
41
|
14 |
|
Graph\Graph::directed((string) $dependency) |
|
42
|
14 |
|
->fillWithColor(RGBA::fromString('#ffb600')) |
|
43
|
14 |
|
->displayAs((string) $dependency), |
|
44
|
14 |
|
static function(Graph $graph, ServiceName $service, Constructor $constructor) use ($dependency): Graph { |
|
45
|
14 |
|
return $graph->add(Element::dependency( |
|
46
|
14 |
|
$dependency, |
|
47
|
14 |
|
$service, |
|
48
|
14 |
|
$constructor |
|
49
|
|
|
)); |
|
50
|
14 |
|
} |
|
51
|
|
|
); |
|
52
|
14 |
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
public function isDirected(): bool |
|
55
|
|
|
{ |
|
56
|
2 |
|
return $this->graph->isDirected(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function name(): Name |
|
60
|
|
|
{ |
|
61
|
2 |
|
return $this->graph->name(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
public function cluster(Graph $cluster): Graph |
|
65
|
|
|
{ |
|
66
|
1 |
|
return $this->graph->cluster($cluster); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function clusters(): SetInterface |
|
73
|
|
|
{ |
|
74
|
2 |
|
return $this->graph->clusters(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
public function add(Node $node): Graph |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->graph->add($node); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function roots(): SetInterface |
|
86
|
|
|
{ |
|
87
|
3 |
|
return $this->graph->roots(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function nodes(): SetInterface |
|
94
|
|
|
{ |
|
95
|
2 |
|
return $this->graph->nodes(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
1 |
|
public function displayAs(string $label): Graph |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->graph->displayAs($label); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function fillWithColor(RGBA $color): Graph |
|
104
|
|
|
{ |
|
105
|
1 |
|
return $this->graph->fillWithColor($color); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function colorizeBorderWith(RGBA $color): Graph |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->graph->colorizeBorderWith($color); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
public function target(UrlInterface $url): Graph |
|
114
|
|
|
{ |
|
115
|
1 |
|
return $this->graph->target($url); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
6 |
|
public function attributes(): MapInterface |
|
122
|
|
|
{ |
|
123
|
6 |
|
return $this->graph->attributes(); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|