public function testSetWhere() { $push = new LeanPush(array("alert" => "Hello world!")); $query = new LeanQuery("_Installation"); $date = new DateTime(); $query->lessThan("updatedAt", $date); $push->setWhere($query); $out = $push->encode(); $this->assertEquals(array("updatedAt" => array('$lt' => LeanClient::encode($date))), $out["where"]); }
/** * Field equals to a value * * Equal-to condition is the strongest constraint overall, it has * higher precedence than all other conditions. All prior * conditions set on the field will be discarded and of no effect * when adding an equal-to condition. * * @param string $key * @param mixed $val * @return self */ public function equalTo($key, $val) { $this->where[$key] = LeanClient::encode($val); return $this; }
public function testEncodeCircularObjectAsPointer() { $a = new LeanObject("TestObject", "id001"); $b = new LeanObject("TestObject", "id002"); $c = new LeanObject("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 = LeanClient::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"]); }
/** * Get unsaved data * * @return array Deep associative array */ private function getSaveData() { return LeanClient::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) { $params = $body; if ($decodeObj) { $params = LeanClient::decode($body, null); } $meta["remoteAddress"] = $this->env["REMOTE_ADDR"]; try { $result = Cloud::run($funcName, $params, LeanUser::getCurrentUser(), $meta); } catch (FunctionError $err) { $this->renderError($err->getMessage(), $err->getCode()); } if ($decodeObj) { // Encode object to full, type-annotated JSON $out = LeanClient::encode($result, "toFullJSON"); } else { // Encode object to type-less literal JSON $out = LeanClient::encode($result, "toJSON"); } $this->renderJSON(array("result" => $out)); }
/** * Encode to JSON represented operation * * @return array */ public function encode() { return LeanClient::encode($this->value); }
/** * Encode to JSON represented operation * * @return array */ public function encode() { return array("__op" => $this->getOpType(), "objects" => LeanClient::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(LeanClient::encode($pvalues)); } $resp = LeanClient::get('/cloudQuery', $data); $objects = array(); foreach ($resp["results"] as $val) { $obj = LeanObject::create($resp["className"], $val["objectId"]); $obj->mergeAfterFetch($val); $objects[] = $obj; } $resp["results"] = $objects; return $resp; }