mirror of
https://github.com/YGGverse/net-php.git
synced 2025-01-27 15:14:29 +00:00
fix square quoting for fsockopen
This commit is contained in:
parent
cc9ddf3647
commit
0d840357e6
@ -6,15 +6,30 @@ namespace Yggverse\Net;
|
||||
|
||||
class Socket
|
||||
{
|
||||
public static function isIPv4(mixed $value): bool
|
||||
{
|
||||
return false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
|
||||
}
|
||||
|
||||
public static function isIPv6(mixed $value): bool
|
||||
{
|
||||
return false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
||||
}
|
||||
|
||||
public static function isHostName(mixed $value): bool
|
||||
{
|
||||
return false !== filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
||||
}
|
||||
|
||||
public static function isHost(mixed $value): bool
|
||||
{
|
||||
return
|
||||
(
|
||||
is_string($value) &&
|
||||
(
|
||||
false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ||
|
||||
false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ||
|
||||
false !== filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
|
||||
false !== self::isIPv4($value) ||
|
||||
false !== self::isIPv6($value) ||
|
||||
false !== self::isHostName($value)
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -37,7 +52,7 @@ class Socket
|
||||
if (self::isHost($host) && self::isPort($port))
|
||||
{
|
||||
$connection = @fsockopen(
|
||||
$host,
|
||||
self::isIPv6($host) ? "[$host]" : $host, // PHP is shit 💩.
|
||||
$port,
|
||||
$error_code,
|
||||
$error_message,
|
||||
|
Loading…
x
Reference in New Issue
Block a user