|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the doctrineviz package |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2017 Pierre Hennequart |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* Feel free to edit as you please, and have fun. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Pierre Hennequart <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
declare(strict_types=1); |
|
17
|
|
|
|
|
18
|
|
|
namespace Janalis\Doctrineviz\Graphviz; |
|
19
|
|
|
|
|
20
|
|
|
class Edge implements EdgeInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use Attributable; |
|
23
|
|
|
|
|
24
|
|
|
/** @var ElementInterface */ |
|
25
|
|
|
protected $from; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ElementInterface */ |
|
28
|
|
|
protected $to; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
protected $label; |
|
32
|
|
|
|
|
33
|
|
|
/* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __toString() |
|
37
|
|
|
{ |
|
38
|
|
|
return "{$this->getId($this->from)} -> {$this->getId($this->to)}".(!count($this->getAttributes()) ? '' : ' ['.PHP_EOL. |
|
39
|
|
|
implode(PHP_EOL, $this->indentAll($this->getAttributes())). |
|
40
|
|
|
PHP_EOL.']').';'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get attributes. |
|
45
|
|
|
* |
|
46
|
|
|
* @return AttributeInterface[] |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getAttributes(): array |
|
49
|
|
|
{ |
|
50
|
|
|
if (null !== $this->label) { |
|
51
|
|
|
$this->createAttribute('label', $this->label); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this->attributes ? array_values($this->attributes) : []; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get vertex id. |
|
59
|
|
|
* |
|
60
|
|
|
* @param ElementInterface $element |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getId(ElementInterface $element): string |
|
65
|
|
|
{ |
|
66
|
|
|
return $element instanceof RecordInterface ? "{$element->getVertex()->getId()}:{$element->getId()}" : "{$element->getId()}"; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Edge constructor. |
|
71
|
|
|
* |
|
72
|
|
|
* @param ElementInterface|null $from |
|
73
|
|
|
* @param ElementInterface|null $to |
|
74
|
|
|
* @param null|string $label |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct(ElementInterface $from = null, ElementInterface $to = null, string $label = null) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->from = $from; |
|
79
|
|
|
$this->to = $to; |
|
80
|
|
|
$this->label = $label; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get from. |
|
85
|
|
|
* |
|
86
|
|
|
* @return ElementInterface|null |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getFrom(): ?ElementInterface |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->from; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Set from. |
|
95
|
|
|
* |
|
96
|
|
|
* @param ElementInterface $from |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setFrom(ElementInterface $from): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->from = $from; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get to. |
|
105
|
|
|
* |
|
106
|
|
|
* @return ElementInterface|null |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getTo(): ?ElementInterface |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->to; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Set to. |
|
115
|
|
|
* |
|
116
|
|
|
* @param ElementInterface $to |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setTo($to): void |
|
119
|
|
|
{ |
|
120
|
|
|
$this->to = $to; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get label. |
|
125
|
|
|
* |
|
126
|
|
|
* @return string|null |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getLabel(): ?string |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->label; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set label. |
|
135
|
|
|
* |
|
136
|
|
|
* @param string|null $label |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setLabel(string $label = null): void |
|
139
|
|
|
{ |
|
140
|
|
|
$this->label = $label; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|