Exemplo n.º 1
0
 public function testDeleteTestObject()
 {
     $data = LeanClient::post("/classes/TestObject", array("name" => "alice", "story" => "in wonderland"));
     $this->assertArrayHasKey("objectId", $data);
     LeanClient::delete("/classes/TestObject/{$data['objectId']}");
     $obj = LeanClient::get("/classes/TestObject/{$data['objectId']}");
     $this->assertEmpty($obj);
 }
Exemplo n.º 2
0
 public function testAddUniqueOnAddField()
 {
     $obj = array("name" => "alice", "tags" => array("__op" => "Add", "objects" => array("frontend", "frontend")));
     $resp = LeanClient::post("/classes/TestObject", $obj);
     $this->assertNotEmpty($resp["objectId"]);
     $resp2 = LeanClient::get("/classes/TestObject/{$resp["objectId"]}");
     $this->assertEquals(array("frontend", "frontend"), $resp2["tags"]);
     $resp3 = LeanClient::put("/classes/TestObject/{$resp["objectId"]}", array("tags" => array("__op" => "AddUnique", "objects" => array("css"))));
     // AddUnique will not remove exsiting duplicate items
     $resp4 = LeanClient::get("/classes/TestObject/{$resp["objectId"]}");
     $this->assertEquals(array("frontend", "frontend", "css"), $resp4["tags"]);
     LeanClient::delete("/classes/TestObject/{$resp['objectId']}");
 }
Exemplo n.º 3
0
 /**
  * Count number of objects by the query
  *
  * @return int
  */
 public function count()
 {
     $params = $this->encode();
     $params["limit"] = 0;
     $params["count"] = 1;
     $resp = LeanClient::get("/classes/{$this->getClassName()}", $params);
     return $resp["count"];
 }
Exemplo n.º 4
0
 /**
  * Fetch file object by id
  *
  * Note it fetches descriptive data from LeanCloud, but not file content.
  * The content should be fetched from file URL.
  *
  * @return LeanFile
  */
 public static function fetch($objectId)
 {
     $file = new LeanFile("");
     $resp = LeanClient::get("/files/{$objectId}");
     $file->mergeAfterFetch($resp);
     return $file;
 }
Exemplo n.º 5
0
 public function testUserLogin()
 {
     $data = array("username" => "testuser", "password" => "5akf#a?^G", "phone" => "18612340000");
     $resp = LeanClient::post("/users", $data);
     $this->assertNotEmpty($resp["objectId"]);
     $this->assertNotEmpty($resp["sessionToken"]);
     $id = $resp["objectId"];
     $resp = LeanClient::get("/users/me", array("session_token" => $resp["sessionToken"]));
     $this->assertNotEmpty($resp["objectId"]);
     LeanClient::delete("/users/{$id}", $resp["sessionToken"]);
     // Raise 211: Could not find user.
     $this->setExpectedException("LeanCloud\\CloudException", null, 211);
     $resp = LeanClient::get("/users/me", array("session_token" => "non-existent-token"));
 }
Exemplo n.º 6
0
 /**
  * Log-in user by mobile phone and SMS code.
  *
  * Log-in user with SMS code, which can be requested by
  * `requestLoginSmsCode`. It will set current user.
  *
  * @param string $phoneNumber Registered mobile phone number
  * @param string $smsCode
  * @return LeanUser
  */
 public static function logInWithSmsCode($phoneNumber, $smsCode)
 {
     $params = array("mobilePhoneNumber" => $phoneNumber, "smsCode" => $smsCode);
     $resp = LeanClient::get("/login", $params);
     $user = new static();
     static::saveCurrentUser($user);
     return $user;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }