File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use OutOfRangeException ;
6
6
use UnitPhpSdk \Contracts \UpstreamInterface ;
7
+ use UnitPhpSdk \Exceptions \UnitException ;
7
8
use UnitPhpSdk \Traits \HasListeners ;
8
9
9
10
/**
@@ -46,13 +47,18 @@ private function setServers(array $servers): void
46
47
* @param string $ip
47
48
* @param int $weight
48
49
* @return void
50
+ * @throws UnitException
49
51
*/
50
52
public function setServer (string $ ip , int $ weight = 1 ): void
51
53
{
52
54
if ($ weight < 0 || $ weight > 1000000 ) {
53
55
throw new OutOfRangeException ('Weight should be between 0 and 1000000 ' );
54
56
}
55
57
58
+ if (!filter_var ($ ip , FILTER_VALIDATE_IP )) {
59
+ throw new UnitException ("{$ ip } isn't a valid IP address " );
60
+ }
61
+
56
62
$ this ->_servers [$ ip ] = [
57
63
'weight ' => $ weight
58
64
];
You can’t perform that action at this time.
0 commit comments