word() public static method

Build word (2 bytes) big-endian
public static word ( integer $int ) : string
$int integer Integer
return string
Ejemplo n.º 1
0
 /**
  * Gets the host information
  * @param  string   $hostname Hostname
  * @param  callable $cb       Callback
  * @callback $cb ( )
  * @return void
  */
 public function get($hostname, $cb)
 {
     $this->onResponse->push($cb);
     $this->setFree(false);
     $e = explode(':', $hostname, 3);
     $hostname = $e[0];
     $qtype = isset($e[1]) ? $e[1] : 'A';
     $qclass = isset($e[2]) ? $e[2] : 'IN';
     $QD = [];
     $qtypeInt = array_search($qtype, Pool::$type, true);
     $qclassInt = array_search($qclass, Pool::$class, true);
     if ($qtypeInt === false || $qclassInt === false) {
         call_user_func($cb, false);
         return;
     }
     $q = Binary::labels($hostname) . Binary::word($qtypeInt) . Binary::word($qclassInt);
     $QD[] = $q;
     $packet = Binary::word(++$this->seq) . Binary::bitmap2bytes('0' . '0000' . '0' . '0' . '1' . '0' . '000' . '0000', 2) . Binary::word(sizeof($QD)) . Binary::word(0) . Binary::word(0) . Binary::word(0) . implode('', $QD);
     if ($this->type === 'udp') {
         $this->write($packet);
     } else {
         $this->write(Binary::word(strlen($packet)) . $packet);
     }
 }