Skip to content

Commit b9529d0

Browse files
Add ip validation
1 parent d60cb9b commit b9529d0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Config/Upstream.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use OutOfRangeException;
66
use UnitPhpSdk\Contracts\UpstreamInterface;
7+
use UnitPhpSdk\Exceptions\UnitException;
78
use UnitPhpSdk\Traits\HasListeners;
89

910
/**
@@ -46,13 +47,18 @@ private function setServers(array $servers): void
4647
* @param string $ip
4748
* @param int $weight
4849
* @return void
50+
* @throws UnitException
4951
*/
5052
public function setServer(string $ip, int $weight = 1): void
5153
{
5254
if ($weight < 0 || $weight > 1000000) {
5355
throw new OutOfRangeException('Weight should be between 0 and 1000000');
5456
}
5557

58+
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
59+
throw new UnitException("{$ip} isn't a valid IP address");
60+
}
61+
5662
$this->_servers[$ip] = [
5763
'weight' => $weight
5864
];

0 commit comments

Comments
 (0)