![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/spomky-labs/pki-framework/src/X509/GeneralName/ |
<?php declare(strict_types=1); namespace SpomkyLabs\Pki\X509\GeneralName; use function array_slice; use function count; use UnexpectedValueException; final class IPv4Address extends IPAddress { public static function create(string $ip, ?string $mask = null): self { return new self($ip, $mask); } /** * Initialize from octets. */ public static function fromOctets(string $octets): self { $mask = null; $bytes = unpack('C*', $octets); $bytes = $bytes === false ? [] : $bytes; switch (count($bytes)) { case 4: $ip = implode('.', $bytes); break; case 8: $ip = implode('.', array_slice($bytes, 0, 4)); $mask = implode('.', array_slice($bytes, 4, 4)); break; default: throw new UnexpectedValueException('Invalid IPv4 octet length.'); } return self::create($ip, $mask); } protected function octets(): string { $bytes = array_map('intval', explode('.', $this->ip)); if (isset($this->mask)) { $bytes = array_merge($bytes, array_map('intval', explode('.', $this->mask))); } return pack('C*', ...$bytes); } }