Skip to content

Commit 5c78b15

Browse files
committed
Merge pull request #50 from juvenn/v0.2
发布 0.2.3 : 修复 getCurrentUser 循环调用问题
2 parents 49a3780 + fd47ceb commit 5c78b15

6 files changed

Lines changed: 35 additions & 5 deletions

File tree

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
0.2.3 发布日期:2016-01-12
3+
----
4+
5+
* 修复 getCurrentUser 循环调用问题 close #48
6+
27
0.2.2 发布日期:2016-01-06
38
----
49

src/LeanCloud/LeanClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LeanClient {
2222
/**
2323
* Client version
2424
*/
25-
const VERSION = '0.2.2';
25+
const VERSION = '0.2.3';
2626

2727
/**
2828
* API Endpoints for Regions

src/LeanCloud/LeanFile.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ public function __construct($name, $data=null, $mimeType=null) {
5757
}
5858
$this->_data["mime_type"] = $mimeType;
5959

60-
$user = LeanUser::getCurrentUser();
61-
$this->_metaData["owner"] = $user ? $user->getObjectId() : "unknown";
60+
$this->_metaData["owner"] = "unknown";
61+
if (LeanUser::$currentUser) {
62+
$this->_metaData["owner"] = LeanUser::$currentUser->getObjectId();
63+
}
6264
if ($this->_source) {
6365
$this->_metaData["size"] = strlen($this->_source);
6466
}

src/LeanCloud/LeanUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LeanUser extends LeanObject {
4949
*
5050
* @var LeanUser
5151
*/
52-
protected static $currentUser = null;
52+
public static $currentUser = null;
5353

5454
/**
5555
* Set username
@@ -185,7 +185,7 @@ public function getSessionToken() {
185185
*
186186
* @param string $token Session token of logged-in user
187187
*/
188-
protected static function setCurrentSessionToken($token) {
188+
public static function setCurrentSessionToken($token) {
189189
LeanClient::getStorage()->set("LC_SessionToken", $token);
190190
}
191191

tests/LeanFileTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ public function testSaveObjectWithFile() {
110110
$file->destroy();
111111
$obj->destroy();
112112
}
113+
113114
}
114115

tests/LeanUserTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use LeanCloud\LeanClient;
44
use LeanCloud\LeanUser;
5+
use LeanCloud\LeanFile;
56
use LeanCloud\CloudException;
67
use LeanCloud\Storage\SessionStorage;
78

@@ -176,5 +177,26 @@ public function testUnlinkService() {
176177
$user2->destroy();
177178
}
178179

180+
/*
181+
* Get current user with file attribute will result
182+
* circular invoking getCurrentUser.
183+
*
184+
* @link github.com/leancloud/php-sdk#48
185+
*/
186+
public function testCircularGetCurrentUser() {
187+
// ensure getCurrentUser neither run indefinetely, nor throw maximum
188+
// function all error
189+
$avatar = LeanFile::createWithUrl("alice.png", "https://leancloud.cn/favicon.png");
190+
$user = LeanUser::logIn("alice", "blabla");
191+
$user->set("avatar", $avatar);
192+
$user->save();
193+
$token = LeanUser::getCurrentSessionToken();
194+
$user->logOut();
195+
LeanUser::setCurrentSessionToken($token);
196+
197+
$user2 = LeanUser::getCurrentUser();
198+
$this->assertEquals($user2->getUsername(), "alice");
199+
}
200+
179201
}
180202

0 commit comments

Comments
 (0)