/** * Delete objects in batch * * @param array $objects Array of Objects to destroy */ public static function destroyAll($objects) { $batch = array(); foreach ($objects as $obj) { if (!$obj->getObjectId()) { throw new \RuntimeException("Cannot destroy object without ID"); } // Remove duplicate objects by ID $batch[$obj->getObjectId()] = $obj; } if (empty($batch)) { return; } $requests = array(); $objects = array(); foreach ($batch as $obj) { $requests[] = array("path" => "/1.1/classes/{$obj->getClassName()}" . "/{$obj->getObjectId()}", "method" => "DELETE"); $objects[] = $obj; } $sessionToken = User::getCurrentSessionToken(); $response = Client::batch($requests, $sessionToken); }
/** * Build authentication headers * * @param string $sessionToken Session token of a User * @param bool $useMasterKey * @return array */ public static function buildHeaders($sessionToken, $useMasterKey) { if (is_null($useMasterKey)) { $useMasterKey = self::$useMasterKey; } $h = self::$defaultHeaders; $h['X-LC-Prod'] = self::$isProduction ? 1 : 0; $timestamp = time(); $key = $useMasterKey ? self::$appMasterKey : self::$appKey; $sign = md5($timestamp . $key); $h['X-LC-Sign'] = $sign . "," . $timestamp; if ($useMasterKey) { $h['X-LC-Sign'] .= ",master"; } if (!$sessionToken) { $sessionToken = User::getCurrentSessionToken(); } if ($sessionToken) { $h['X-LC-Session'] = $sessionToken; } return $h; }
public function testCircularGetCurrentUser() { // ensure getCurrentUser neither run indefinetely, nor throw maximum // function call error $avatar = File::createWithUrl("alice.png", "https://leancloud.cn/favicon.png"); $user = User::logIn("alice", "blabla"); $user->set("avatar", $avatar); $user->save(); $token = User::getCurrentSessionToken(); $user->logOut(); User::setCurrentSessionToken($token); $user2 = User::getCurrentUser(); $this->assertEquals($user2->getUsername(), "alice"); }