public function testConvertRecursive() { $this->assertEqual(Bert_Encoder::convert(Bert::t(Bert::t(true), false)), Bert::t(Bert::t(Bert::t(Bert::a('bert'), Bert::a('true'))), Bert::t(Bert::a('bert'), Bert::a('false')))); }
public function readComplexType() { $val = $this->readAnyRaw(); if ($val == Bert::a('nil')) { return null; } elseif ($val == Bert::a('true')) { return true; } elseif ($val == Bert::a('false')) { return false; } elseif ($val == Bert::a('time')) { return new Bert_Time($this->readAnyRaw(), $this->readAnyRaw(), $this->readAnyRaw()); } elseif ($val == Bert::a('regex')) { $source = $this->readAnyRaw(); $opts = $this->readAnyRaw(); $options = array(); foreach ($opts as $name) { $options[] = "{$name}"; } return new Bert_Regex($source, $options); } elseif ($val == Bert::a('dict')) { return $this->readDict(); } else { return null; } }
public static function start() { $input = fopen("php://fd/3", 'r'); $output = fopen("php://fd/4", 'w'); while (true) { $obj = self::readBerp($input); if (!isset($obj)) { echo "Could not read BERP length header. Ernie server may have gone away. Exiting now.\n"; exit(1); } if (count($obj) == 4 && $obj[0] == 'call') { $mod = $obj[1]; $fun = $obj[2]; $args = $obj[3]; try { $result = self::dispatch($mod, $fun, $args); $response = Bert::t(Bert::a('reply'), $result); self::writeBerp($output, $response); } catch (Ernie_ServerError $e) { $response = Bert::t(Bert::a('error'), Bert::t(Bert::a('server'), 0, get_class($e), $e->getMessage(), $e->getTrace())); self::writeBerp($output, $response); } catch (Exception $e) { $response = Bert::t(Bert::a('error'), Bert::t(Bert::a('user'), 0, get_class($e), $e->getMessage(), $e->getTrace())); self::writeBerp($output, $response); } } elseif (count($obj) == 4 && $obj[0] == 'cast') { $mod = $obj[1]; $fun = $obj[2]; $args = $obj[3]; try { $result = self::dispatch($mod, $fun, $args); } catch (Exception $e) { // ignore } self::writeBerp($output, Bert::t(Bert::a('noreply'))); } else { $outObj = Bert::t(Bert::a('error'), array(Bert::a('server'), 0, "Invalid request: " . print_r($obj, true))); self::writeBerp($output, $outObj); } } }
public function cast($options = null) { $this->_verifyOptions($options); return new Bert_Rpc_Request($this, Bert::a('cast'), $options); }