public function testSetWhere() { $push = new Push(array("alert" => "Hello world!")); $query = new Query("_Installation"); $date = new DateTime(); $query->lessThan("updatedAt", $date); $push->setWhere($query); $out = $push->encode(); $this->assertEquals(array("updatedAt" => array('$lt' => Client::encode($date))), $out["where"]); }
/** * Encode to JSON represented operation * * @return array */ public function encode() { return array("__op" => $this->getOpType(), "objects" => Client::encode($this->value)); }
/** * Doing a CQL query to retrive objects * * It returns an array that contains: * * * className - Class name of the query * * results - List of objects * * count - Number of objects when it's a count query * * @param string $cql CQL statement * @param array $pvalues Positional values to replace in CQL * @return array * @link https://leancloud.cn/docs/cql_guide.html */ public static function doCloudQuery($cql, $pvalues = array()) { $data = array("cql" => $cql); if (!empty($pvalues)) { $data["pvalues"] = json_encode(Client::encode($pvalues)); } $resp = Client::get('/cloudQuery', $data); $objects = array(); foreach ($resp["results"] as $val) { $obj = Object::create($resp["className"], $val["objectId"]); $obj->mergeAfterFetch($val); $objects[] = $obj; } $resp["results"] = $objects; return $resp; }
/** * Get unsaved changes * * @return array */ private function getSaveData() { return Client::encode($this->_operationSet); }
/** * Dispatch function and render result * * @param string $funcName Function name * @param array $body JSON decoded body params * @param bool $decodeObj */ private function dispatchFunc($funcName, $body, $decodeObj = false) { // verify hook sign for RTM hooks if (in_array($funcName, array('_messageReceived', '_receiversOffline', '_messageSent', '_conversationStart', '_conversationStarted', '_conversationAdd', '_conversationRemove', '_conversationUpdate'))) { if (!Client::verifyHookSign($funcName, $body["__sign"])) { error_log("Invalid hook sign for message {$funcName}" . " from {$this->env['REMOTE_ADDR']}"); $this->renderError("Unauthorized.", 401, 401); } } $params = $body; if ($decodeObj) { $params = Client::decode($body, null); } $meta["remoteAddress"] = $this->env["REMOTE_ADDR"]; try { $result = Cloud::run($funcName, $params, User::getCurrentUser(), $meta); } catch (FunctionError $err) { $this->renderError($err->getMessage(), $err->getCode()); } if ($decodeObj) { // Encode object to full, type-annotated JSON $out = Client::encode($result, "toFullJSON"); } else { // Encode object to type-less literal JSON $out = Client::encode($result, "toJSON"); } $this->renderJSON(array("result" => $out)); }
public function testEncodeCircularObjectAsPointer() { $a = new Object("TestObject", "id001"); $b = new Object("TestObject", "id002"); $c = new Object("TestObject", "id003"); $a->set("name", "A"); $b->set("name", "B"); $c->set("name", "C"); $a->addIn("likes", $b); $b->addIn("likes", $c); $c->addIn("likes", $a); $jsonA = Client::encode($a, "toFullJSON"); $jsonB = $jsonA["likes"][0]; $jsonC = $jsonB["likes"][0]; $this->assertEquals("Object", $jsonA["__type"]); $this->assertEquals("Object", $jsonB["__type"]); $this->assertEquals("Object", $jsonC["__type"]); $this->assertEquals("Pointer", $jsonC["likes"][0]["__type"]); }
/** * Encode to JSON represented operation * * @return array */ public function encode() { return Client::encode($this->value); }