public function testDecodeGeoPoint() { $type = array('__type' => 'GeoPoint', 'latitude' => 39.9, 'longitude' => 116.4); $val = LeanClient::decode($type, null); $this->assertTrue($val instanceof GeoPoint); $this->assertEquals(39.9, $val->getLatitude()); $this->assertEquals(116.4, $val->getLongitude()); }
/** * Merge data and metaData from server response * * @param array $data * @param array $meta Optional meta data */ private function _mergeData($data, $meta = array()) { // manually convert createdAt and updatedAt fields so they'll // be decoded as DateTime object. foreach (array("createdAt", "updatedAt") as $key) { if (isset($data[$key]) && is_string($data[$key])) { $data[$key] = array("__type" => "Date", "iso" => $data[$key]); } } foreach ($data as $key => $val) { $this->_data[$key] = LeanClient::decode($val, $key); } foreach ($meta as $key => $val) { $this->_metaData[$key] = LeanClient::decode($val, $key); } }
/** * Merge data from server * * @param array $data JSON decoded server response * @return void */ private function _mergeData($data) { foreach ($data as $key => $val) { $this->_data[$key] = LeanClient::decode($val); } }
public function testDecodeFile() { $type = array("__type" => "File", "objectId" => "abc101", "name" => "favicon.ico", "url" => "https://leancloud.cn/favicon.ico"); $val = LeanClient::decode($type); $this->assertTrue($val instanceof LeanFile); $this->assertEquals($type["objectId"], $val->getObjectId()); $this->assertEquals($type["name"], $val->getName()); $this->assertEquals($type["url"], $val->getUrl()); }
/** * Dispatch onLogin hook * * @param array $body JSON decoded body params */ private function dispatchOnLogin($body) { $userObj = LeanClient::decode($body["object"], null); $meta["remoteAddress"] = $this->env["REMOTE_ADDR"]; try { Cloud::runOnLogin($userObj, $meta); } catch (FunctionError $err) { $this->renderError($err->getMessage(), $err->getCode()); } $this->renderJSON(array("result" => "ok")); }
public function testDecodeBytes() { $type = array("__type" => "Bytes", "base64" => base64_encode("Hello")); $val = LeanClient::decode($type); $this->assertTrue($val instanceof LeanBytes); $this->assertEquals(array(72, 101, 108, 108, 111), $val->getByteArray()); }