Пример #1
0
 public function testGetVersion()
 {
     $ip4 = new IPAddress('127.0.0.1');
     $this->assertSame(IPAddressVersion::IPV4(), $ip4->getVersion());
     $ip6 = new IPAddress('::1');
     $this->assertSame(IPAddressVersion::IPV6(), $ip6->getVersion());
 }
Пример #2
0
 /**
  * Returns the version (IPv4 or IPv6) of the ip address
  *
  * @return IPAddressVersion
  */
 public function getVersion()
 {
     $isIPv4 = filter_var($this->toNative(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
     if (false !== $isIPv4) {
         return IPAddressVersion::IPV4();
     }
     return IPAddressVersion::IPV6();
 }