22
33namespace Qcloud \Cos ;
44
5+ use Exception ;
56use Qcloud \Cos \Signature ;
67use GuzzleHttp \Client as HttpClient ;
78use GuzzleHttp \HandlerStack ;
1617use GuzzleHttp \Exception \ConnectException ;
1718use GuzzleHttp \Middleware ;
1819use 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