|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7.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 attributes |
|
18
|
|
|
*/ |
|
19
|
|
|
class Edge implements HasDotRepresentation |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var HasNodeIdentifier */ |
|
22
|
|
|
private $fromNode; |
|
23
|
|
|
|
|
24
|
|
|
/** @var HasNodeIdentifier */ |
|
25
|
|
|
private $toNode; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $options; |
|
29
|
|
|
|
|
30
|
90 |
|
public function __construct( |
|
31
|
|
|
HasNodeIdentifier $nodeA, |
|
32
|
|
|
HasNodeIdentifier $nodeB, |
|
33
|
|
|
string $options |
|
34
|
|
|
) { |
|
35
|
90 |
|
$this->fromNode = $nodeA; |
|
36
|
90 |
|
$this->toNode = $nodeB; |
|
37
|
90 |
|
$this->options = $options; |
|
38
|
90 |
|
} |
|
39
|
|
|
|
|
40
|
57 |
|
public static function inheritance(HasNodeIdentifier $parent, HasNodeIdentifier $child): Edge |
|
41
|
|
|
{ |
|
42
|
57 |
|
return new Edge($parent, $child, 'dir=back arrowtail=empty style=solid'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
51 |
|
public static function implementation(HasNodeIdentifier $interface, HasNodeIdentifier $class): Edge |
|
46
|
|
|
{ |
|
47
|
51 |
|
return new Edge($interface, $class, 'dir=back arrowtail=empty style=dashed'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
51 |
|
public static function association(HasNodeIdentifier $reference, HasNodeIdentifier $class): Edge |
|
51
|
|
|
{ |
|
52
|
51 |
|
return new Edge($reference, $class, 'dir=back arrowtail=none style=solid'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* A trait can be used by another trait or a class |
|
57
|
|
|
*/ |
|
58
|
42 |
|
public static function use(HasNodeIdentifier $trait, HasNodeIdentifier $definition): Edge |
|
59
|
|
|
{ |
|
60
|
42 |
|
return new Edge($trait, $definition, 'dir=back arrowtail=normal style=solid'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
63 |
|
public function fromNode(): HasNodeIdentifier |
|
64
|
|
|
{ |
|
65
|
63 |
|
return $this->fromNode; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
63 |
|
public function toNode(): HasNodeIdentifier |
|
69
|
|
|
{ |
|
70
|
63 |
|
return $this->toNode; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
54 |
|
public function options(): string |
|
74
|
|
|
{ |
|
75
|
54 |
|
return $this->options; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
57 |
|
public function dotTemplate(): string |
|
79
|
|
|
{ |
|
80
|
57 |
|
return 'edge'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|