Skip to content

Commit 23b84a8

Browse files
authored
Merge pull request #94 from tharropoulos/static-nodes
fix(api_call): use instance-based nodes instead of static ones
2 parents 0e8dee5 + d080e99 commit 23b84a8

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/ApiCall.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class ApiCall
4646
/**
4747
* @var array|Node[]
4848
*/
49-
private static array $nodes;
49+
private array $nodes;
5050

5151
/**
5252
* @var Node|null
5353
*/
54-
private static ?Node $nearestNode;
54+
private ?Node $nearestNode;
5555

5656
/**
5757
* @var int
@@ -73,8 +73,8 @@ public function __construct(Configuration $config)
7373
$this->config = $config;
7474
$this->logger = $config->getLogger();
7575
$this->client = $config->getClient();
76-
static::$nodes = $this->config->getNodes();
77-
static::$nearestNode = $this->config->getNearestNode();
76+
$this->nodes = $this->config->getNodes();
77+
$this->nearestNode = $this->config->getNearestNode();
7878
$this->nodeIndex = 0;
7979
$this->initializeNodes();
8080
}
@@ -84,11 +84,11 @@ public function __construct(Configuration $config)
8484
*/
8585
private function initializeNodes(): void
8686
{
87-
if (static::$nearestNode !== null) {
88-
$this->setNodeHealthCheck(static::$nearestNode, true);
87+
if ($this->nearestNode !== null) {
88+
$this->setNodeHealthCheck($this->nearestNode, true);
8989
}
9090

91-
foreach (static::$nodes as &$node) {
91+
foreach ($this->nodes as &$node) {
9292
$this->setNodeHealthCheck($node, true);
9393
}
9494
}
@@ -332,16 +332,16 @@ public function setNodeHealthCheck(Node $node, bool $isHealthy): void
332332
*/
333333
public function getNode(): Lib\Node
334334
{
335-
if (static::$nearestNode !== null) {
336-
if (static::$nearestNode->isHealthy() || $this->nodeDueForHealthCheck(static::$nearestNode)) {
337-
return static::$nearestNode;
335+
if ($this->nearestNode !== null) {
336+
if ($this->nearestNode->isHealthy() || $this->nodeDueForHealthCheck($this->nearestNode)) {
337+
return $this->nearestNode;
338338
}
339339
}
340340
$i = 0;
341-
while ($i < count(static::$nodes)) {
341+
while ($i < count($this->nodes)) {
342342
$i++;
343-
$node = static::$nodes[$this->nodeIndex];
344-
$this->nodeIndex = ($this->nodeIndex + 1) % count(static::$nodes);
343+
$node = $this->nodes[$this->nodeIndex];
344+
$this->nodeIndex = ($this->nodeIndex + 1) % count($this->nodes);
345345
if ($node->isHealthy() || $this->nodeDueForHealthCheck($node)) {
346346
return $node;
347347
}
@@ -351,7 +351,7 @@ public function getNode(): Lib\Node
351351
* None of the nodes are marked healthy, but some of them could have become healthy since last health check.
352352
* So we will just return the next node.
353353
*/
354-
return static::$nodes[$this->nodeIndex];
354+
return $this->nodes[$this->nodeIndex];
355355
}
356356

357357
/**

0 commit comments

Comments
 (0)