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