Skip to content

Commit 69c6fec

Browse files
lewzylulewzylu
andauthored
add input check (#197)
Co-authored-by: lewzylu <[email protected]>
1 parent 32bc51b commit 69c6fec

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Qcloud/Cos/Client.php

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

33
namespace Qcloud\Cos;
44

5+
use Exception;
56
use Qcloud\Cos\Signature;
67
use GuzzleHttp\Client as HttpClient;
78
use GuzzleHttp\HandlerStack;
@@ -16,6 +17,7 @@
1617
use GuzzleHttp\Exception\ConnectException;
1718
use GuzzleHttp\Middleware;
1819
use GuzzleHttp\Psr7;
20+
use Qcloud\Cos\Exception\CosException;
1921

2022
/**
2123
* @method object AbortMultipartUpload (array $arg)
@@ -105,7 +107,7 @@ class Client extends GuzzleClient {
105107
public function __construct($cosConfig) {
106108
$this->rawCosConfig = $cosConfig;
107109
$this->cosConfig['schema'] = isset($cosConfig['schema']) ? $cosConfig['schema'] : 'http';
108-
$this->cosConfig['region'] = region_map($cosConfig['region']);
110+
$this->cosConfig['region'] = isset($cosConfig['region']) ? region_map($cosConfig['region']) : null;
109111
$this->cosConfig['appId'] = isset($cosConfig['credentials']['appId']) ? $cosConfig['credentials']['appId'] : null;
110112
$this->cosConfig['secretId'] = isset($cosConfig['credentials']['secretId']) ? $cosConfig['credentials']['secretId'] : "";
111113
$this->cosConfig['secretKey'] = isset($cosConfig['credentials']['secretKey']) ? $cosConfig['credentials']['secretKey'] : "";
@@ -122,7 +124,11 @@ public function __construct($cosConfig) {
122124
$this->cosConfig['userAgent'] = isset($cosConfig['userAgent']) ? $cosConfig['userAgent'] : 'cos-php-sdk-v5.'. Client::VERSION;
123125
$this->cosConfig['pathStyle'] = isset($cosConfig['pathStyle']) ? $cosConfig['pathStyle'] : false;
124126
$this->cosConfig['allow_redirects'] = isset($cosConfig['allow_redirects']) ? $cosConfig['allow_redirects'] : false;
125-
127+
try {
128+
$this->inputCheck();
129+
} catch (\Exception $e) {
130+
throw($e);
131+
}
126132
$service = Service::getService();
127133
$handler = HandlerStack::create();
128134
$handler->push(Middleware::retry($this->retryDecide(), $this->retryDelay()));
@@ -152,6 +158,19 @@ public function __construct($cosConfig) {
152158
'commandToRequestTransformer'], [$this, 'responseToResultTransformer'],
153159
null);
154160
}
161+
162+
public function inputCheck() {
163+
if ($this->cosConfig['region'] == null &&
164+
$this->cosConfig['domain'] == null &&
165+
$this->cosConfig['endpoint'] == null &&
166+
$this->cosConfig['ip'] == null) {
167+
$e = new \Qcloud\Cos\Exception\CosException("Region is empty");
168+
$e->setExceptionCode("Invalid Argument");
169+
throw $e;
170+
}
171+
}
172+
173+
155174
public function retryDecide() {
156175
return function (
157176
$retries,

0 commit comments

Comments
 (0)