|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Compose\Visualization\Node; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Compose\Definition\{ |
|
7
|
|
|
Name as ServiceName, |
|
8
|
|
|
Service, |
|
9
|
|
|
Service\Constructor, |
|
10
|
|
|
Argument |
|
11
|
|
|
}; |
|
12
|
|
|
use Innmind\Graphviz\{ |
|
13
|
|
|
Node, |
|
14
|
|
|
Edge, |
|
15
|
|
|
Node\Name, |
|
16
|
|
|
Node\Shape |
|
17
|
|
|
}; |
|
18
|
|
|
use Innmind\Url\UrlInterface; |
|
19
|
|
|
use Innmind\Colour\Colour; |
|
20
|
|
|
use Innmind\Immutable\{ |
|
21
|
|
|
MapInterface, |
|
22
|
|
|
SetInterface, |
|
23
|
|
|
Str |
|
24
|
|
|
}; |
|
25
|
|
|
|
|
26
|
|
|
final class Element implements Node |
|
27
|
|
|
{ |
|
28
|
|
|
private $node; |
|
29
|
|
|
|
|
30
|
35 |
|
private function __construct(Node $node) |
|
31
|
|
|
{ |
|
32
|
35 |
|
$this->node = $node; |
|
33
|
35 |
|
} |
|
34
|
|
|
|
|
35
|
23 |
|
public static function dependency( |
|
36
|
|
|
ServiceName $dependency, |
|
37
|
|
|
ServiceName $name, |
|
38
|
|
|
Constructor $constructor |
|
39
|
|
|
): self { |
|
40
|
23 |
|
$constructor = Str::of((string) $constructor)->replace('\\', '\\\\'); |
|
41
|
|
|
|
|
42
|
23 |
|
$node = self::build($dependency->add($name)); |
|
43
|
23 |
|
$node->displayAs( |
|
44
|
23 |
|
(string) Str::of((string) $name)->append( |
|
45
|
23 |
|
'\n('.$constructor.')' |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
23 |
|
return new self($node); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
public static function service(Service $service): self |
|
53
|
|
|
{ |
|
54
|
2 |
|
$constructor = Str::of((string) $service->constructor())->replace('\\', '\\\\'); |
|
55
|
|
|
|
|
56
|
2 |
|
$node = self::build($service->name()); |
|
57
|
2 |
|
$node->displayAs( |
|
58
|
2 |
|
(string) Str::of((string) $service->name())->append( |
|
59
|
2 |
|
'\n('.$constructor.')' |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
2 |
|
if ($service->exposed()) { |
|
64
|
1 |
|
$node->shaped( |
|
65
|
1 |
|
Shape::house()->fillWithColor(Colour::fromString('#0f0')) |
|
|
|
|
|
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
return new self($node); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
14 |
|
public static function argument(Argument $argument): self |
|
73
|
|
|
{ |
|
74
|
14 |
|
$node = self::build($argument->name()); |
|
75
|
14 |
|
$node->displayAs( |
|
76
|
14 |
|
(string) Str::of((string) $argument->name()) |
|
77
|
14 |
|
->append('\n('.$argument->type().')') |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
14 |
|
return new self($node); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
35 |
|
public static function build(ServiceName $name): Node |
|
84
|
|
|
{ |
|
85
|
35 |
|
return Node\Node::named( |
|
86
|
35 |
|
(string) Str::of((string) $name)->replace('.', '_') |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
7 |
|
public function name(): Name |
|
91
|
|
|
{ |
|
92
|
7 |
|
return $this->node->name(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
5 |
|
public function edges(): SetInterface |
|
99
|
|
|
{ |
|
100
|
5 |
|
return $this->node->edges(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
2 |
|
public function linkedTo(Node $node): Edge |
|
104
|
|
|
{ |
|
105
|
2 |
|
return $this->node->linkedTo($node); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function target(UrlInterface $url): Node |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->node->target($url); |
|
111
|
|
|
} |
|
112
|
1 |
|
public function displayAs(string $label): Node |
|
113
|
|
|
{ |
|
114
|
1 |
|
return $this->node->displayAs($label); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
1 |
|
public function shaped(Shape $shape): Node |
|
118
|
|
|
{ |
|
119
|
1 |
|
return $this->node->shaped($shape); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
4 |
|
public function hasAttributes(): bool |
|
123
|
|
|
{ |
|
124
|
4 |
|
return $this->node->hasAttributes(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
8 |
|
public function attributes(): MapInterface |
|
131
|
|
|
{ |
|
132
|
8 |
|
return $this->node->attributes(); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|