1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the bisarca/graph package. |
5
|
|
|
* |
6
|
|
|
* (c) Emanuele Minotto <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bisarca\Graph\Edge; |
13
|
|
|
|
14
|
|
|
use Bisarca\Graph\Attribute\AttributeAwareInterface; |
15
|
|
|
use Bisarca\Graph\Attribute\AttributeAwareTrait; |
16
|
|
|
use Bisarca\Graph\Vertex\VertexInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Basic edge implementation. |
20
|
|
|
*/ |
21
|
|
|
class Edge implements EdgeInterface, AttributeAwareInterface |
22
|
|
|
{ |
23
|
|
|
use AttributeAwareTrait; |
24
|
|
|
use Descriptor\LoopTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Starting vertex. |
28
|
|
|
* |
29
|
|
|
* @var VertexInterface|null |
30
|
|
|
*/ |
31
|
|
|
private $vertexStart; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Ending vertex. |
35
|
|
|
* |
36
|
|
|
* @var VertexInterface|null |
37
|
|
|
*/ |
38
|
|
|
private $vertexEnd; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
VertexInterface $vertexStart = null, |
45
|
|
|
VertexInterface $vertexEnd = null |
46
|
|
|
) { |
47
|
|
|
$this->vertexStart = $vertexStart; |
48
|
|
|
$this->vertexEnd = $vertexEnd; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function hasVertexStart(): bool |
55
|
|
|
{ |
56
|
|
|
return null !== $this->vertexStart; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function getVertexStart(): VertexInterface |
63
|
|
|
{ |
64
|
|
|
return $this->vertexStart; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function setVertexStart(VertexInterface $vertexStart) |
71
|
|
|
{ |
72
|
|
|
$this->vertexStart = $vertexStart; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function hasVertexEnd(): bool |
79
|
|
|
{ |
80
|
|
|
return null !== $this->vertexEnd; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function getVertexEnd(): VertexInterface |
87
|
|
|
{ |
88
|
|
|
return $this->vertexEnd; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function setVertexEnd(VertexInterface $vertexEnd) |
95
|
|
|
{ |
96
|
|
|
$this->vertexEnd = $vertexEnd; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|