1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smoren\GraphTools\Conditions\Traits; |
4
|
|
|
|
5
|
|
|
use Smoren\GraphTools\Conditions\Interfaces\VertexConditionInterface; |
6
|
|
|
use Smoren\GraphTools\Models\Interfaces\VertexInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trait for vertex condition implementation |
10
|
|
|
* @implements VertexConditionInterface<mixed> |
11
|
|
|
* @property array<string>|null $vertexTypesOnly vertex types whitelist |
12
|
|
|
* @property array<string> $vertexTypesExclude vertex types blacklist |
13
|
|
|
* @property array<string>|null $vertexIdsOnly vertex ids whitelist |
14
|
|
|
* @property array<string> $vertexIdsExclude vertex ids blacklist |
15
|
|
|
*/ |
16
|
|
|
trait VertexConditionTrait |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @inheritDoc |
20
|
|
|
*/ |
21
|
|
|
public function getVertexTypesOnly(): ?array |
22
|
|
|
{ |
23
|
|
|
return $this->vertexTypesOnly; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
|
|
public function getVertexTypesExcluded(): array |
30
|
|
|
{ |
31
|
|
|
return $this->vertexTypesExclude; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritDoc |
36
|
|
|
*/ |
37
|
|
|
public function getVertexIdsOnly(): ?array |
38
|
|
|
{ |
39
|
|
|
return $this->vertexIdsOnly; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
|
|
public function getVertexIdsExcluded(): array |
46
|
|
|
{ |
47
|
|
|
return $this->vertexIdsExclude; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritDoc |
52
|
|
|
*/ |
53
|
|
|
public function onlyVertexTypes(?array $types): self |
54
|
|
|
{ |
55
|
|
|
$this->vertexTypesOnly = $types; |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function excludeVertexTypes(array $types): self |
63
|
|
|
{ |
64
|
|
|
$this->vertexTypesExclude = $types; |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritDoc |
70
|
|
|
*/ |
71
|
|
|
public function onlyVertexIds(?array $ids): self |
72
|
|
|
{ |
73
|
|
|
$this->vertexIdsOnly = $ids; |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritDoc |
79
|
|
|
*/ |
80
|
|
|
public function excludeVertexIds(array $ids): self |
81
|
|
|
{ |
82
|
|
|
$this->vertexIdsExclude = $ids; |
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritDoc |
88
|
|
|
*/ |
89
|
|
|
public function isSuitableVertex(VertexInterface $vertex): bool |
90
|
|
|
{ |
91
|
|
|
if($this->vertexTypesOnly !== null && !in_array($vertex->getType(), $this->vertexTypesOnly)) { |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if($this->vertexIdsOnly !== null && !in_array($vertex->getId(), $this->vertexIdsOnly)) { |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if(in_array($vertex->getType(), $this->vertexTypesExclude)) { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if(in_array($vertex->getId(), $this->vertexIdsExclude)) { |
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|