Skip to content

Commit 5aeee75

Browse files
committed
Add priority flag for each entry
1 parent b7498d9 commit 5aeee75

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ConnectionManager/Extra/Multiple/ConnectionManagerSelective.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@ public function getConnection($host, $port)
1717
return $this->getConnectionManagerFor($host, $port)->getConnection($host, $port);
1818
}
1919

20-
public function addConnectionManagerFor($connectionManager, $targetHost=self::MATCH_ALL, $targetPort=self::MATCH_ALL)
20+
public function addConnectionManagerFor($connectionManager, $targetHost=self::MATCH_ALL, $targetPort=self::MATCH_ALL, $priority=0)
2121
{
2222
$this->targets []= array(
2323
'connectionManager' => $connectionManager,
2424
'matchHost' => $this->createMatcherHost($targetHost),
2525
'matchPort' => $this->createMatcherPort($targetPort),
26-
'host' => $targetHost,
27-
'port' => $targetPort
26+
'host' => $targetHost,
27+
'port' => $targetPort,
28+
'priority' => $priority
2829
);
2930

3031
// return the key as new entry ID
3132
end($this->targets);
32-
return key($this->targets);
33+
$id = key($this->targets);
34+
35+
// sort array by priority
36+
uasort($this->targets, function ($a, $b) {
37+
return ($a['priority'] < $b['priority'] ? -1 : ($a['priority'] > $b['priority'] ? 1 : 0));
38+
});
39+
40+
return $id;
3341
}
3442

3543
public function getConnectionManagerEntries()

0 commit comments

Comments
 (0)