1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Redislabs\Module\RedisGraph; |
6
|
|
|
|
7
|
|
|
use SevenEcks\Tableify\Tableify; |
8
|
|
|
|
9
|
|
|
class Result |
10
|
|
|
{ |
11
|
|
|
private ?array $resultSet; |
12
|
|
|
private array $statistics; |
13
|
|
|
private ?array $labels; |
14
|
|
|
|
15
|
|
|
public function __construct(?array $labels, ?array $resultSet, Statistics $statistics) |
16
|
|
|
{ |
17
|
|
|
$this->labels = $labels; |
18
|
|
|
$this->resultSet = $resultSet; |
19
|
|
|
$this->statistics = $statistics->getResultStatistics(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public static function createFromResponse(array $response): self |
23
|
|
|
{ |
24
|
|
|
$stats = $response[2] ?? $response[0]; |
25
|
|
|
$resultKeys = isset($response[1]) ? $response[0] : []; |
26
|
|
|
$resultSet = $response[1] ?? []; |
27
|
|
|
return new self($resultKeys, $resultSet, new Statistics($stats)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getResultSet(): array |
31
|
|
|
{ |
32
|
|
|
return $this->resultSet; |
|
|
|
|
33
|
|
|
} |
34
|
|
|
public function getLabels(): array |
35
|
|
|
{ |
36
|
|
|
return $this->labels; |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function getLabelsAdded(): int |
41
|
|
|
{ |
42
|
|
|
return $this->statistics['LABELS_ADDED']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getNodesCreated(): int |
46
|
|
|
{ |
47
|
|
|
return $this->statistics['NODES_CREATED']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getNodesDeleted(): int |
51
|
|
|
{ |
52
|
|
|
return $this->statistics['NODES_DELETED']; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getRelationshipsCreated(): int |
56
|
|
|
{ |
57
|
|
|
return $this->statistics['RELATIONSHIPS_CREATED']; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getRelationshipsDeleted(): int |
61
|
|
|
{ |
62
|
|
|
return $this->statistics['RELATIONSHIPS_DELETED']; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getExecutionTime(): float |
66
|
|
|
{ |
67
|
|
|
return $this->statistics['INTERNAL_EXECUTION_TIME']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPropertiesSet(): int |
71
|
|
|
{ |
72
|
|
|
return $this->statistics['PROPERTIES_SET']; |
73
|
|
|
} |
74
|
|
|
public function getCachedExecution(): int |
75
|
|
|
{ |
76
|
|
|
return $this->statistics['CACHED_EXECUTION']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function prettyPrint(): void |
80
|
|
|
{ |
81
|
|
|
$table = Tableify::new(array_merge([$this->labels], $this->resultSet)); |
|
|
|
|
82
|
|
|
$table = $table->make(); |
83
|
|
|
$tableData = $table->toArray(); |
84
|
|
|
foreach ($tableData as $row) { |
85
|
|
|
echo $row . "\n"; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|