Browse Source

fix square quoting for fsockopen

main 1.1.2
ghost 1 year ago
parent
commit
0d840357e6
  1. 23
      src/Socket.php

23
src/Socket.php

@ -6,15 +6,30 @@ namespace Yggverse\Net; @@ -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 @@ -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…
Cancel
Save