コード例 #1
0
ファイル: Address.php プロジェクト: KikFinder/Subnettr
 /**
  * Create an instance from either a dotted quad (#.#.#.#) or an array
  *
  * @param $address
  * @throws \IPAddress\Exceptions\InvalidFormatException
  */
 public function __construct($address)
 {
     if ($address instanceof Address) {
         $this->address = $address->address;
         return;
     }
     if (is_string($address)) {
         $address = explode(".", $address);
         if (count($address) == 1) {
             $address = Utility::parseUint($address[0], 32);
         }
     }
     if (is_integer($address) || is_float($address)) {
         $address = Utility::parseUint((int) $address, 32);
         $address = array(0xff & ($address >> 24) % 256, 0xff & ($address >> 16) % 256, 0xff & ($address >> 8) % 256, 0xff & $address % 256);
     }
     if (is_array($address) && count($address) == 4) {
         $this->address = array(Utility::parseUint($address[0], 8), Utility::parseUint($address[1], 8), Utility::parseUint($address[2], 8), Utility::parseUint($address[3], 8));
         return;
     }
     throw new InvalidFormatException("Invalid IP address specified");
 }
コード例 #2
0
ファイル: UtilityTest.php プロジェクト: KikFinder/Subnettr
 /**
  * @dataProvider validUints
  *
  * @param $value
  * @param $bits
  * @param $number
  */
 public function testValidNumbers($value, $bits, $number)
 {
     $this->assertEquals($number, Utility::parseUint($value, $bits));
 }