1010namespace PhpComp \Http \Client ;
1111
1212use Closure ;
13- use Exception ;
1413use InvalidArgumentException ;
1514use Psr \Http \Message \RequestInterface ;
1615use Psr \Http \Message \ResponseInterface ;
@@ -208,7 +207,7 @@ public function __destruct()
208207 /**
209208 * @return array
210209 */
211- public static function getSupportedMethods ()
210+ public static function getSupportedMethods (): array
212211 {
213212 return self ::$ supportedMethods ;
214213 }
@@ -308,8 +307,6 @@ public function trace(string $url, $params = null, array $headers = [], array $o
308307 * @param RequestInterface $request
309308 *
310309 * @return ResponseInterface
311- *
312- * @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
313310 */
314311 public function sendRequest (RequestInterface $ request ): ResponseInterface
315312 {
@@ -323,6 +320,23 @@ public function sendRequest(RequestInterface $request): ResponseInterface
323320 return $ this ->getPsr7Response ();
324321 }
325322
323+ /**
324+ * @param string $url
325+ * @param mixed $data
326+ * @param array $headers
327+ * @param array $options
328+ *
329+ * @return ClientInterface
330+ */
331+ public function json (string $ url , $ data = null , array $ headers = [], array $ options = []): ClientInterface
332+ {
333+ if (!isset ($ options ['method ' ])) {
334+ $ options ['method ' ] = 'POST ' ;
335+ }
336+
337+ return $ this ->byJson ()->request ($ url , $ data , $ options ['method ' ], $ headers , $ options );
338+ }
339+
326340 /**
327341 * File download and save
328342 *
@@ -363,7 +377,7 @@ public function getTimeout(): int
363377 *
364378 * @return $this
365379 */
366- public function setTimeout (int $ seconds )
380+ public function setTimeout (int $ seconds ): self
367381 {
368382 $ this ->options ['timeout ' ] = $ seconds ;
369383 return $ this ;
@@ -374,7 +388,7 @@ public function setTimeout(int $seconds)
374388 *
375389 * @return $this
376390 */
377- public function SSLVerify (bool $ enable )
391+ public function SSLVerify (bool $ enable ): self
378392 {
379393 $ this ->options ['sslVerify ' ] = $ enable ;
380394 return $ this ;
@@ -435,7 +449,7 @@ public function acceptGzip()
435449 /**
436450 * @return $this
437451 */
438- public function byJson ()
452+ public function byJson (): self
439453 {
440454 $ this ->setHeader ('Content-Type ' , 'application/json; charset=utf-8 ' );
441455 return $ this ;
@@ -444,15 +458,15 @@ public function byJson()
444458 /**
445459 * @return $this
446460 */
447- public function byXhr ()
461+ public function byXhr (): self
448462 {
449463 return $ this ->byAjax ();
450464 }
451465
452466 /**
453467 * @return $this
454468 */
455- public function byAjax ()
469+ public function byAjax (): self
456470 {
457471 $ this ->setHeader ('X-Requested-With ' , 'XMLHttpRequest ' );
458472 return $ this ;
@@ -478,7 +492,7 @@ public function setUserAgent(string $userAgent): ClientInterface
478492 *
479493 * @return $this
480494 */
481- public function setUserAuth (string $ user , string $ pwd = '' , int $ authType = self ::AUTH_BASIC )
495+ public function setUserAuth (string $ user , string $ pwd = '' , int $ authType = self ::AUTH_BASIC ): AbstractClient
482496 {
483497 if ($ authType === self ::AUTH_BASIC ) {
484498 $ sign = 'Basic ' . base64_encode ("$ user: $ pwd " );
@@ -613,7 +627,7 @@ public function delHeader($names): ClientInterface
613627 *
614628 * @return string
615629 */
616- protected function buildFullUrl (string $ url , $ data = null )
630+ protected function buildFullUrl (string $ url , $ data = null ): string
617631 {
618632 $ url = trim ($ url );
619633
@@ -775,7 +789,7 @@ public function getBaseUrl(): string
775789
776790 /**
777791 * @param int|string $name
778- * @param bool $default
792+ * @param null $default
779793 *
780794 * @return mixed
781795 */
0 commit comments