public function buzz($s = \HACKLIB_UNINIT) { if ($s === \HACKLIB_UNINIT) { $s = \HH\Map::hacklib_new(array('a'), array('z')); } echo join(", ", (array) \hacklib_cast_as_array($s)) . "\n"; }
public function getHandlerContext($fn_name) { $context = \HH\Map::hacklib_new(array(), array()); foreach ($this->handlers as $key => $handler) { $context[$key] = $handler->getHandlerContext($fn_name); } return $context; }
echo "({$t}) {$i} : {$out}\n"; } $i = $m->getIterator(); $i->next(); $i->next(); $i->next(); $i->next(); try { $i->current(); echo "should not see this"; } catch (InvalidOperationException $e) { echo $e->getMessage() . "\n"; } } $immMap = \HH\ImmMap::hacklib_new(array("25", 9, "9"), array("Galadriel", true, new Foo())); $map = \HH\Map::hacklib_new(array("25", 9, "keyai"), array("zinc", 99, array(2 => 2))); verify_map($immMap); verify_map($map); $i = $map->getIterator(); $map[\hacklib_id("25")] = "copper"; echo "key is " . $i->key() . "\n"; $map[\hacklib_id("logo")] = "basic"; try { $i->key(); echo "should not see this"; } catch (InvalidOperationException $e) { echo $e->getMessage() . "\n"; } $map = $map->add(\HH\Pair::hacklib_new("tweedledee", "tweedledum")); foreach ($map as $i => $mal) { $out = var_export($mal, true);
private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 15; const Green = "green"; } echo "ImmVector: "; var_dump(E2::assertAll(new \HH\ImmVector(array(15, "15", "12", 12, "green")))); echo "array: "; var_dump(E2::assertAll(array(15, "15", "12", 12, "green"))); echo "Map: "; var_dump(E2::assertAll(\HH\Map::hacklib_new(array(12, "1", 1, "grey", 3), array(15, "15", "12", 12, "green")))); function fn() { $a = array(15, "15", "12", 12, "green"); foreach ($a as $v) { (yield $v); } } $g = fn(); echo "Generator: "; var_dump(E2::assertAll($g)); try { E2::assertAll(array(15, "true", 12)); } catch (\UnexpectedValueException $e) { echo $e->getMessage() . "\n"; }
function test_all_containers() { $data_arr = array(1, 2, 3); test_container(array()); test_container($data_arr); test_container(new \HH\ImmVector(array())); test_container(new \HH\ImmVector($data_arr)); test_container(new \HH\Vector(array())); test_container(new \HH\Vector($data_arr)); test_container(\HH\Pair::hacklib_new(1, 2)); test_container(new \HH\ImmSet(array())); test_container(new \HH\ImmSet($data_arr)); test_container(new \HH\Set(array())); test_container(new \HH\Set($data_arr)); test_container(\HH\ImmMap::hacklib_new(array(), array())); test_container(new \HH\ImmMap($data_arr)); test_container(\HH\Map::hacklib_new(array(), array())); test_container(new \HH\Map($data_arr)); test_container(new Foo()); }
public static function hacklib_initialize_statics() { self::$c = \HH\Map::hacklib_new(array("do", "re", "mi"), array("a deer", "a drop", "a name")); }
{ 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))));
public function __construct() { $this->handlers = \HH\Map::hacklib_new(array(), array()); }
private function flushImpl($oneway) { if (\hacklib_equals(strlen($this->wBuf_), 0)) { if (\hacklib_cast_as_boolean($oneway)) { $this->transport_->onewayFlush(); } else { $this->transport_->flush(); } return; } $out = $this->transform($this->wBuf_); $this->wBuf_ = ''; if ($this->protoId_ === 1 && $this->clientType_ !== self::HTTP_CLIENT_TYPE) { throw new TTransportException('Trying to send JSON encoding over binary', TTransportException::INVALID_CLIENT); } $buf = ''; if ($this->clientType_ === self::HEADER_CLIENT_TYPE) { $transformData = ''; $num_headers = 0; foreach ($this->writeTrans_ as $trans) { ++$num_headers; $transformData .= $this->getVarint($trans); } if ($this->identity !== null) { $this->writeHeaders[self::ID_VERSION_HEADER] = (string) self::ID_VERSION; $this->writeHeaders[self::IDENTITY_HEADER] = $this->identity; } $infoData = ''; if (\hacklib_cast_as_boolean($this->writeHeaders) || \hacklib_cast_as_boolean($this->persistentWriteHeaders)) { $infoData .= $this->getVarint(self::INFO_KEYVALUE); $infoData .= $this->getVarint(count($this->writeHeaders) + count($this->persistentWriteHeaders)); foreach ($this->persistentWriteHeaders as $str_key => $str_value) { $infoData .= $this->writeString($str_key); $infoData .= $this->writeString($str_value); } foreach ($this->writeHeaders as $str_key => $str_value) { $infoData .= $this->writeString($str_key); $infoData .= $this->writeString($str_value); } } $this->writeHeaders = \HH\Map::hacklib_new(array(), array()); $headerData = $this->getVarint($this->protoId_) . $this->getVarint($num_headers); $header_size = strlen($transformData) + strlen($infoData) + strlen($headerData); $paddingSize = 4 - $header_size % 4; $header_size += $paddingSize; $buf = (string) pack('nn', self::HEADER_MAGIC, $this->flags_); $buf .= (string) pack('Nn', $this->seqId_, $header_size / 4); $buf .= $headerData . $transformData; $buf .= $infoData; for ($i = 0; $i < $paddingSize; $i++) { $buf .= (string) pack('C', '\\0'); } $buf .= $out; $buf = (string) pack('N', strlen($buf)) . $buf; } else { if ($this->clientType_ === self::FRAMED_DEPRECATED) { $buf = (string) pack('N', strlen($out)); $buf .= $out; } else { if ($this->clientType_ === self::UNFRAMED_DEPRECATED) { $buf = $out; } else { if ($this->clientType_ === self::HTTP_CLIENT_TYPE) { throw new TTransportException('HTTP not implemented', TTransportException::INVALID_CLIENT); } else { throw new TTransportException('Unknown client type', TTransportException::INVALID_CLIENT); } } } } if (strlen($buf) > self::MAX_FRAME_SIZE) { throw new TTransportException('Attempting to send oversize frame', TTransportException::INVALID_FRAME_SIZE); } $this->transport_->write($buf); if (\hacklib_cast_as_boolean($oneway)) { $this->transport_->onewayFlush(); } else { $this->transport_->flush(); } }
protected static final function hacklib_initialize_statics_t3() { self::hacklib_initialize_statics_t1(); self::$c = \HH\Map::hacklib_new(array("uu"), array("qq")); }
<?php require_once $GLOBALS['HACKLIB_ROOT']; function check_array_cast($c) { $arr = (array) \hacklib_cast_as_array($c); echo \hacklib_cast_as_boolean(is_array($arr)) ? "YES\n" : "NO\n"; echo count($arr) . "\n"; } check_array_cast(new \HH\Vector(array())); check_array_cast(new \HH\ImmVector(array("hey", "few"))); check_array_cast(\HH\Map::hacklib_new(array("do", "doo"), array("be", "bee")));
<?php namespace blah { require_once $GLOBALS['HACKLIB_ROOT']; $v = \HH\Vector::fromItems(array(1, 2, 3)); echo $v->count() . "\n"; $s = \HH\Set::fromKeysOf(\HH\Map::hacklib_new(array("abc"), array("123"))); echo \hacklib_cast_as_boolean($s->contains("abc")) ? "yes it does\n" : "no it doesnt\n"; } namespace { $m = \HH\Map::fromArray(array("foo" => "bar")); echo $m->count() . "\n"; }