1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 8.1 |
4
|
|
|
* |
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace PhUml\Graphviz; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* An edge represents 1 of 3 types of relationships between classes and interfaces |
12
|
|
|
* |
13
|
|
|
* 1. Inheritance |
14
|
|
|
* 2. Interface implementation |
15
|
|
|
* 3. Associations |
16
|
|
|
* - Via constructor injection |
17
|
|
|
* - Via class properties |
18
|
|
|
*/ |
19
|
|
|
final class Edge implements HasDotRepresentation |
20
|
|
|
{ |
21
|
15 |
|
public static function inheritance(HasNodeIdentifier $parent, HasNodeIdentifier $child): Edge |
22
|
|
|
{ |
23
|
15 |
|
return new Edge($parent, $child, 'dir=back arrowtail=empty style=solid'); |
24
|
|
|
} |
25
|
|
|
|
26
|
13 |
|
public static function implementation(HasNodeIdentifier $interface, HasNodeIdentifier $class): Edge |
27
|
|
|
{ |
28
|
13 |
|
return new Edge($interface, $class, 'dir=back arrowtail=empty style=dashed'); |
29
|
|
|
} |
30
|
|
|
|
31
|
16 |
|
public static function association(HasNodeIdentifier $reference, HasNodeIdentifier $class): Edge |
32
|
|
|
{ |
33
|
16 |
|
return new Edge($reference, $class, 'dir=back arrowtail=none style=solid'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* A trait can be used by another trait or a class |
38
|
|
|
*/ |
39
|
10 |
|
public static function use(HasNodeIdentifier $trait, HasNodeIdentifier $definition): Edge |
40
|
|
|
{ |
41
|
10 |
|
return new Edge($trait, $definition, 'dir=back arrowtail=normal style=solid'); |
42
|
|
|
} |
43
|
|
|
|
44
|
29 |
|
private function __construct( |
45
|
|
|
private readonly HasNodeIdentifier $fromNode, |
|
|
|
|
46
|
|
|
private readonly HasNodeIdentifier $toNode, |
47
|
|
|
private readonly string $options |
48
|
|
|
) { |
49
|
|
|
} |
50
|
|
|
|
51
|
17 |
|
public function fromNode(): HasNodeIdentifier |
52
|
|
|
{ |
53
|
17 |
|
return $this->fromNode; |
54
|
|
|
} |
55
|
|
|
|
56
|
17 |
|
public function toNode(): HasNodeIdentifier |
57
|
|
|
{ |
58
|
17 |
|
return $this->toNode; |
59
|
|
|
} |
60
|
|
|
|
61
|
14 |
|
public function options(): string |
62
|
|
|
{ |
63
|
14 |
|
return $this->options; |
64
|
|
|
} |
65
|
|
|
|
66
|
15 |
|
public function dotTemplate(): string |
67
|
|
|
{ |
68
|
15 |
|
return 'edge'; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|