Skip to content

Commit f82568a

Browse files
committed
Order by priority (or fall back to key position)
1 parent 3d0658c commit f82568a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ConnectionManager/Extra/Multiple/ConnectionManagerSelective.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public function addConnectionManagerFor($connectionManager, $targetHost=self::MA
4040
$id = key($this->targets);
4141

4242
// sort array by priority
43-
uasort($this->targets, function ($a, $b) {
44-
return ($a['priority'] < $b['priority'] ? -1 : ($a['priority'] > $b['priority'] ? 1 : 0));
43+
$targets &= $this->targets;
44+
uksort($this->targets, function ($a, $b) use ($targets) {
45+
$pa = $targets[$a]['priority'];
46+
$pb = $targets[$b]['priority'];
47+
return ($pa < $pb ? -1 : ($pa > $pb ? 1 : ($b - $a)));
4548
});
4649

4750
return $id;

0 commit comments

Comments
 (0)