-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from juvenn/master
Merge from v0.2 branch
- Loading branch information
Showing
14 changed files
with
231 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ language: php | |
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
|
||
env: | ||
- LC_API_REGION=US | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ use LeanCloud\LeanUser; | |
use LeanCloud\CloudException; | ||
|
||
$user = new LeanUser(); | ||
$user->setUsername("alice"): | ||
$user->setUsername("alice"); | ||
$user->setEmail("[email protected]"); | ||
$user->setPassword("passpass"); | ||
try { | ||
|
@@ -228,7 +228,7 @@ try { | |
} | ||
``` | ||
|
||
完整的 API 文档请参考: https://leancloud.cn/docs/api/php/ | ||
完整的 API 文档请参考: https://leancloud.cn/api-docs/php | ||
|
||
贡献 | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace LeanCloud; | ||
|
||
/** | ||
* BatchRequestError | ||
* | ||
* A BatchRequestError object consists of zero or more request and | ||
* response errors. | ||
* | ||
*/ | ||
class BatchRequestError extends CloudException { | ||
|
||
/** | ||
* Array of error response | ||
* | ||
* @var array | ||
*/ | ||
private $errors; | ||
|
||
public function __construct($message="", $code = 1) { | ||
$message = empty($message) ? "Batch request error." : $message; | ||
parent::__construct($message, $code); | ||
} | ||
|
||
/** | ||
* Add failed request and its error response | ||
* | ||
* Both request and response are expected to be array. The response | ||
* array must contain an `error` message, while the request should | ||
* contain `method` and `path`. | ||
* | ||
* @return BatchRequestError | ||
*/ | ||
public function add($request, $response) { | ||
if (!isset($response["error"])) { | ||
throw new \InvalidArgumentException("Invalid error response."); | ||
} | ||
if (!isset($response["code"])) { | ||
$response["code"] = 1; | ||
} | ||
$response["request"] = $request; | ||
$this->errors[] = $response; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get all error response | ||
* | ||
* @return array | ||
*/ | ||
public function getAll() { | ||
return $this->errors; | ||
} | ||
|
||
/** | ||
* Get first error response as map | ||
* | ||
* Returns associative array of following format: | ||
* | ||
* `{"code": 101, "error": "error message", "request": {...}}` | ||
* | ||
* @return array|null | ||
*/ | ||
public function getFirst() { | ||
return isset($this->errors[0]) ? $this->errors[0] : null; | ||
} | ||
|
||
/** | ||
* Contains error response or not | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmpty() { | ||
return count($this->errors) == 0; | ||
} | ||
|
||
public function __toString() { | ||
$message = $this->message; | ||
if (!$this->isEmpty()) { | ||
$message .= json_encode($this-errors); | ||
} | ||
return __CLASS__ . ": [{$this->code}]: {$message}\n"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.