|
24 | 24 | use Laudis\Neo4j\Enum\AccessMode;
|
25 | 25 | use Laudis\Neo4j\Enum\ConnectionProtocol;
|
26 | 26 | use Laudis\Neo4j\Enum\RoutingRoles;
|
27 |
| -use Laudis\Neo4j\Types\CypherList; |
28 | 27 | use Psr\Http\Message\UriInterface;
|
29 | 28 | use function random_int;
|
30 | 29 | use function str_starts_with;
|
@@ -86,33 +85,40 @@ private function getNextServer(RoutingTable $table, AccessMode $mode): Uri
|
86 | 85 | private function routingTable(ConnectionInterface $connection): RoutingTable
|
87 | 86 | {
|
88 | 87 | if ($this->table === null || $this->table->getTtl() < time()) {
|
| 88 | + /** @var Bolt */ |
89 | 89 | $bolt = $connection->getImplementation();
|
90 | 90 | $protocol = $connection->getProtocol();
|
91 | 91 | if ($protocol->compare(ConnectionProtocol::BOLT_V43()) >= 0) {
|
92 |
| - $route = $bolt->route()['rt']; |
93 |
| - ['servers' => $servers, 'ttl' => $ttl ] = $route; |
| 92 | + /** @var array{rt: array{servers: list<array{addresses: list<string>, role:string}>, ttl: int}} $route */ |
| 93 | + $route = $bolt->route(); |
| 94 | + ['servers' => $servers, 'ttl' => $ttl ] = $route['rt']; |
94 | 95 | } elseif ($protocol->compare(ConnectionProtocol::BOLT_V40()) >= 0) {
|
95 | 96 | $bolt->run('CALL dbms.routing.getRoutingTable({context: []})');
|
| 97 | + /** |
| 98 | + * @var iterable<array{addresses: list<string>, role:string}> $servers |
| 99 | + * @var int $ttl |
| 100 | + */ |
96 | 101 | ['servers' => $servers, 'ttl' => $ttl] = $bolt->pullAll();
|
97 | 102 | } else {
|
98 | 103 | $bolt->run('CALL dbms.cluster.overview()');
|
| 104 | + /** @var list<array{addresses: list<string>, role: string}> */ |
99 | 105 | $response = $bolt->pullAll();
|
100 | 106 |
|
101 | 107 | /** @var iterable<array{addresses: list<string>, role:string}> $servers */
|
102 | 108 | $servers = [];
|
103 | 109 | $ttl = time() + 3600;
|
104 | 110 | foreach ($response as $server) {
|
105 |
| - /** @var CypherList<string> $addresses */ |
106 |
| - $addresses = $server->get('addresses'); |
107 |
| - $addresses = $addresses->filter(static fn (string $x) => str_starts_with($x, 'bolt://')); |
| 111 | + $addresses = $server['addresses']; |
| 112 | + $addresses = array_filter($addresses, static fn (string $x) => str_starts_with($x, 'bolt://')); |
108 | 113 | /**
|
109 | 114 | * @psalm-suppress InvalidArrayAssignment
|
110 | 115 | *
|
111 | 116 | * @var array{addresses: list<string>, role:string}
|
112 | 117 | */
|
113 |
| - $servers[] = ['addresses' => $addresses->toArray(), 'role' => $server->get('role')]; |
| 118 | + $servers[] = ['addresses' => $addresses, 'role' => $server['role']]; |
114 | 119 | }
|
115 | 120 | }
|
| 121 | + |
116 | 122 | $this->table = new RoutingTable($servers, $ttl);
|
117 | 123 | }
|
118 | 124 |
|
|
0 commit comments