Exemplo n.º 1
0
 public function foo()
 {
     $x = 1 + 2 * (3 - 2 / 5);
     $y = -++$x % +10;
     $x -= $y++;
     $y /= --$z;
     $b = "hi" . " hello";
     $c .= "hey there";
     $n = $x-- | $y & ($z ^ ~$x >> 2) << 3;
     $yes = ((bool) \hacklib_cast_as_boolean($x) && $x > $y || !($x >= $z)) ^ $z < $y || $z <= $x;
     $maybe = \hacklib_equals($x, $y) && $x === $y && \hacklib_not_equals($z, $x) && $z !== $y;
 }
Exemplo n.º 2
0
 public function __construct($host, $port = 80, $uri = "", $scheme = "http", $debugHandler = null)
 {
     if (\hacklib_cast_as_boolean($uri) && \hacklib_not_equals($uri[0], "/")) {
         $uri = "/" . $uri;
     }
     $this->scheme_ = $scheme;
     $this->host_ = $host;
     $this->port_ = $port;
     $this->uri_ = $uri;
     $this->buf_ = "";
     $this->data_ = "";
     $this->errstr_ = "";
     $this->timeout_ = null;
     $this->custom_headers_ = null;
     $this->debugHandler_ = \hacklib_cast_as_boolean($debugHandler) ?: fun("error_log");
 }
 public function hacklib_equals($other)
 {
     static $baseClass = array('HH\\Pair' => 'HH\\Pair', 'HH\\Vector' => 'HH\\Vector', 'HH\\ImmVector' => 'HH\\Vector', 'HH\\Set' => 'HH\\Set', 'HH\\ImmSet' => 'HH\\Set', 'HH\\Map' => 'HH\\Map', 'HH\\ImmMap' => 'HH\\Map');
     if (is_bool($other)) {
         return !$this->isEmpty() == $other;
     }
     if (!is_object($other)) {
         return false;
     }
     // We know that our class is in this list.
     if ($baseClass[get_class($this)] != $baseClass[get_class($other)]) {
         return false;
     }
     $otherContainer = $other->__hacklib_getContainer();
     if (count($this->container) != count($otherContainer)) {
         return false;
     }
     foreach ($this->container as $key => $value) {
         if (!array_key_exists($key, $otherContainer) || hacklib_not_equals($value, $otherContainer[$key])) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 4
0
 public function readMessageBegin(&$name, &$type, &$seqid)
 {
     $sz = 0;
     $result = $this->readI32($sz);
     if ($sz < 0) {
         $version = $sz & self::VERSION_MASK;
         if (\hacklib_not_equals($version, self::VERSION_1)) {
             throw new TProtocolException("Bad version identifier: " . $sz, TProtocolException::BAD_VERSION);
         }
         $type = $sz & 0xff;
         $result += $this->readString($name) + $this->readI32($seqid);
     } else {
         if (\hacklib_cast_as_boolean($this->strictRead_)) {
             throw new TProtocolException("No version identifier, old protocol client?", TProtocolException::BAD_VERSION);
         } else {
             if ($this->memory_limit > 0 && $sz > $this->memory_limit) {
                 throw new TProtocolException("Length overflow: " . $sz, TProtocolException::SIZE_LIMIT);
             }
             $name = $this->trans_->readAll($sz);
             $result += $sz + $this->readByte($type) + $this->readI32($seqid);
         }
     }
     $this->sequenceID = $seqid;
     return $result;
 }
Exemplo n.º 5
0
 public function open()
 {
     if (\hacklib_cast_as_boolean($this->ipV6_)) {
         $handle = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
     } else {
         $handle = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     }
     if ($handle === false) {
         $error = "TNonBlockingSocket: Could not create socket";
         throw new TTransportException($error);
     }
     $this->handle_ = $handle;
     if (!\hacklib_cast_as_boolean(socket_set_nonblock($this->handle_))) {
         $error = "TNonBlockingSocket: Could not set nonblocking.";
         throw new TTransportException($error);
     }
     $res = socket_connect($this->handle_, $this->host_, $this->port_);
     if (!\hacklib_cast_as_boolean($res)) {
         $errno = socket_last_error($this->handle_);
         $errstr = socket_strerror($errno);
         $error = "TNonBlockingSocket: socket_connect error (" . (string) $errstr . "[" . (string) $errno . "])";
         if (\hacklib_not_equals($errno, 115)) {
             if (\hacklib_cast_as_boolean($this->debug_)) {
                 call_user_func($this->debugHandler_, $error);
             }
         }
         throw new TTransportException($error);
     }
     $wBuf_ = "";
     $rBuf_ = "";
     $rBufPos_ = 0;
     $this->sockRecvCapacity_ = socket_get_option($this->handle_, SOL_SOCKET, SO_RCVBUF);
     if (\hacklib_equals($this->sockRecvCapacity_, false)) {
         $this->sockRecvCapacity_ = null;
     }
 }
Exemplo n.º 6
0
{
    echo $name . " : " . (\hacklib_cast_as_boolean($c) ? " TRUE " : " FALSE ") . "\n";
}
$o1 = 10;
$o2 = "10";
print_res("straightforward equality", 10 == "10");
print_res("simple equality", \hacklib_equals($o1, $o2));
print_res("simple inequality", \hacklib_not_equals($o1, $o2));
print_res("vec and immvec", \hacklib_equals(new \HH\Vector(array()), new \HH\ImmVector(array())));
$m1 = \HH\Map::hacklib_new(array("t", 1), array("tt", 2));
$m2 = \HH\Map::hacklib_new(array(1, "t"), array(2, "tt"));
print_res("map key order", \hacklib_equals($m1, $m2));
$p1 = \HH\Pair::hacklib_new(1, 2);
$p2 = \HH\Pair::hacklib_new(1, 2);
$p1->getIterator();
print_res("collections with additional state", \hacklib_equals($p1, $p2));
print_res("Pairs can be unequal", \hacklib_not_equals(\HH\Pair::hacklib_new("high", "tea"), \HH\Pair::hacklib_new("high", "tee")));
print_res("Vector uses ==", \hacklib_equals(new \HH\Vector(array(1)), new \HH\ImmVector(array("1"))));
print_res("Even if Empty", \hacklib_equals(new \HH\Vector(array()), new \HH\ImmVector(array())));
print_res("Number of Items", \hacklib_equals(new \HH\Set(array(1)), new \HH\Set(array(1, 2))));
print_res("Sets use === on keys", \hacklib_equals(new \HH\Set(array(1)), new \HH\Set(array("1"))));
print_res("Sets can equal ImmSets", \hacklib_equals(new \HH\Set(array("a", 1)), new \HH\ImmSet(array(1, "a"))));
print_res("Maps do both", \hacklib_equals(\HH\Map::hacklib_new(array("1", 1), array("zork", "mindy")), \HH\Map::hacklib_new(array(1, "1"), array("mindy", "zork"))));
print_res("Maps can equal ImmMaps", \hacklib_equals(\HH\ImmMap::hacklib_new(array("o", 1), array("mork", 1)), \HH\Map::hacklib_new(array(1, "o"), array(1, "mork"))));
print_res("Check for false", \hacklib_equals(new \HH\Vector(array()), false));
print_res("Check for true", \hacklib_equals(true, new \HH\Vector(array())));
print_res("Using not equals", \hacklib_not_equals(\HH\Map::hacklib_new(array(), array()), true));
print_res("Nested Comparison True", \hacklib_equals(new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Vector(array("33")))), new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\ImmVector(array(33))))));
print_res("Nested Comparison False", \hacklib_equals(new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Set(array("33")))), new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Set(array(33))))));
print_res("Compare with null", \hacklib_equals(null, new \HH\Vector(array())));
print_res("Compare values that are null", \hacklib_equals(new \HH\Vector(array(false)), new \HH\Vector(array(null))));
Exemplo n.º 7
0
 public function readMessageBegin(&$name, &$type, &$seqid)
 {
     $protoId = 0;
     $result = $this->readUByte($protoId);
     if (\hacklib_not_equals($protoId, self::PROTOCOL_ID)) {
         throw new TProtocolException("Bad protocol id in TCompact message");
     }
     $verType = 0;
     $result += $this->readUByte($verType);
     $type = ($verType & self::TYPE_MASK) >> self::TYPE_SHIFT_AMOUNT;
     $this->version = $verType & self::VERSION_MASK;
     if (!($this->version <= self::VERSION && $this->version >= self::VERSION_LOW)) {
         throw new TProtocolException("Bad version in TCompact message");
     }
     $result += $this->readVarint($seqid);
     $result += $this->readString($name);
     return $result;
 }