@@ -43,6 +43,7 @@ abstract class AbstractClient implements ClientInterface
4343 * for create psr7 ResponseInterface instance
4444 *
4545 * @var Closure function(): ResponseInterface {..}
46+ * @psalm-var Closure(): ResponseInterface
4647 */
4748 protected $ responseCreator ;
4849
@@ -60,10 +61,10 @@ abstract class AbstractClient implements ClientInterface
6061 // enable SSL verify
6162 'sslVerify ' => false ,
6263 // request headers
63- ' headers ' => [ // name => value
64- ],
65- ' cookies ' => [ // name => value
66- ],
64+ // name => value
65+ ' headers ' => [ ],
66+ // name => value
67+ ' cookies ' => [ ],
6768 'proxy ' => [
6869 // 'host' => '',
6970 // 'port' => '',
@@ -79,14 +80,15 @@ abstract class AbstractClient implements ClientInterface
7980 // send data(todo)
8081 'data ' => [],
8182 'json ' => [],
83+ // extra
8284 // 一些针对不同驱动的自定义选项
8385 // 'curlOptions' => [],
8486 // 'coOptions' => [],
8587 // 'streamContextOptions' => [],
8688 ];
8789
8890 /**
89- * global options data. init from $defaultOptions
91+ * Global options data. init from $defaultOptions
9092 *
9193 * @see AbstractClient::$defaultOptions
9294 * @var array
@@ -110,11 +112,13 @@ abstract class AbstractClient implements ClientInterface
110112 * [ 'Content-Type' => 'Content-Type: application/json' ]
111113 *
112114 * @var array
115+ * @psalm-var array<string, string>
113116 */
114117 protected $ headers = [];
115118
116119 /**
117120 * @var array
121+ * @psalm-var array<string, string>
118122 */
119123 protected $ cookies = [];
120124
@@ -147,6 +151,17 @@ abstract class AbstractClient implements ClientInterface
147151 */
148152 protected $ responseHeaders = [];
149153
154+ /**
155+ * @param array $options
156+ *
157+ * @return static
158+ * @throws RuntimeException
159+ */
160+ public static function new (array $ options = []): ClientInterface
161+ {
162+ return new static ($ options );
163+ }
164+
150165 /**
151166 * @param array $options
152167 *
@@ -158,6 +173,17 @@ public static function create(array $options = []): ClientInterface
158173 return new static ($ options );
159174 }
160175
176+ /**
177+ * @return string
178+ */
179+ public static function driverName (): string
180+ {
181+ $ class = static ::class;
182+ $ name = substr ($ class , strrpos ($ class , '\\' ) + 1 );
183+
184+ return strtolower (str_replace ('Client ' , '' , $ name ));
185+ }
186+
161187 /**
162188 * SimpleCurl constructor.
163189 *
@@ -257,9 +283,9 @@ public function head(string $url, $params = null, array $headers = [], array $op
257283
258284 /**
259285 * @param string $url
260- * @param null $params
261- * @param array $headers
262- * @param array $options
286+ * @param null $params
287+ * @param array $headers
288+ * @param array $options
263289 *
264290 * @return ClientInterface
265291 */
@@ -289,9 +315,9 @@ public function sendRequest(RequestInterface $request): ResponseInterface
289315
290316 /**
291317 * @param string $url
292- * @param mixed $data
293- * @param array $headers
294- * @param array $options
318+ * @param mixed $data
319+ * @param array $headers
320+ * @param array $options
295321 *
296322 * @return ClientInterface
297323 */
@@ -368,14 +394,14 @@ public function SSLVerify(bool $enable): self
368394 /**
369395 * Set contents of HTTP Cookie header.
370396 *
371- * @param string $key The name of the cookie
397+ * @param string $key The name of the cookie
372398 * @param string $value The value for the provided cookie name
373399 *
374400 * @return $this
375401 */
376402 public function setCookie (string $ key , $ value ): ClientInterface
377403 {
378- $ this ->cookies [$ key ] = $ value ;
404+ $ this ->cookies [$ key ] = ( string ) $ value ;
379405 return $ this ;
380406 }
381407
@@ -471,7 +497,7 @@ public function setUserAgent(string $userAgent): ClientInterface
471497 *
472498 * @param string $user
473499 * @param string $pwd
474- * @param int $authType CURLAUTH_BASIC CURLAUTH_DIGEST
500+ * @param int $authType CURLAUTH_BASIC CURLAUTH_DIGEST
475501 *
476502 * @return $this
477503 */
@@ -491,7 +517,7 @@ public function setUserAuth(string $user, string $pwd = '', int $authType = self
491517
492518 /**
493519 * @param string $host
494- * @param int $port
520+ * @param int $port
495521 *
496522 * @return $this
497523 */
@@ -533,7 +559,7 @@ public function setHeaders(array $headers): ClientInterface
533559
534560 /**
535561 * @param array $headers
536- * @param bool $override
562+ * @param bool $override
537563 *
538564 * @return $this
539565 */
@@ -549,7 +575,7 @@ public function addHeaders(array $headers, bool $override = true): ClientInterfa
549575 /**
550576 * @param string $name
551577 * @param string $value
552- * @param bool $override
578+ * @param bool $override
553579 *
554580 * @return $this
555581 */
@@ -588,7 +614,7 @@ public function delHeader($names): ClientInterface
588614
589615 /**
590616 * @param string $url
591- * @param mixed $data
617+ * @param mixed $data
592618 *
593619 * @return string
594620 */
@@ -754,7 +780,7 @@ public function getBaseUrl(): string
754780
755781 /**
756782 * @param int|string $name
757- * @param null $default
783+ * @param null|mixed $default
758784 *
759785 * @return mixed
760786 */
@@ -900,7 +926,7 @@ public function getResponseHeaders(): array
900926
901927 /**
902928 * @param string $name
903- * @param null $default
929+ * @param null $default
904930 *
905931 * @return string
906932 */
@@ -936,6 +962,8 @@ public function isRedirect(): bool
936962
937963 /**
938964 * Was an 'error' returned (client error or server error).
965+ *
966+ * @return bool
939967 */
940968 public function isError (): bool
941969 {
@@ -955,9 +983,6 @@ public function getStatusCode(): int
955983 */
956984 public function getDriverName (): string
957985 {
958- $ class = static ::class;
959- $ name = substr ($ class , strrpos ($ class , '\\' ) + 1 );
960-
961- return strtolower (str_replace ('Client ' , '' , $ name ));
986+ return self ::driverName ();
962987 }
963988}
0 commit comments