正在显示
1 个修改的文件
包含
28 行增加
和
14 行删除
| @@ -18,13 +18,19 @@ class Client extends ServiceManager | @@ -18,13 +18,19 @@ class Client extends ServiceManager | ||
| 18 | 18 | ||
| 19 | private string $requestOption = ''; | 19 | private string $requestOption = ''; |
| 20 | 20 | ||
| 21 | - private bool $withSession = false; | 21 | + private bool $withSession; |
| 22 | 22 | ||
| 23 | - public function __construct(Application $app) | 23 | + public function __construct( |
| 24 | + Application $app, $requestOption = '', $withSession = false | ||
| 25 | + ) | ||
| 24 | { | 26 | { |
| 25 | parent::__construct($app); | 27 | parent::__construct($app); |
| 26 | 28 | ||
| 27 | $this->listen(); | 29 | $this->listen(); |
| 30 | + | ||
| 31 | + $this->requestOption = $requestOption; | ||
| 32 | + | ||
| 33 | + $this->withSession = $withSession; | ||
| 28 | } | 34 | } |
| 29 | 35 | ||
| 30 | protected function listen() | 36 | protected function listen() |
| @@ -37,30 +43,38 @@ class Client extends ServiceManager | @@ -37,30 +43,38 @@ class Client extends ServiceManager | ||
| 37 | 43 | ||
| 38 | public function asForm(): Client | 44 | public function asForm(): Client |
| 39 | { | 45 | { |
| 40 | - $this->requestOption = RequestOptions::FORM_PARAMS; | ||
| 41 | - | ||
| 42 | - return $this; | 46 | + return new Client( |
| 47 | + $this->app, | ||
| 48 | + RequestOptions::FORM_PARAMS, | ||
| 49 | + $this->withSession | ||
| 50 | + ); | ||
| 43 | } | 51 | } |
| 44 | 52 | ||
| 45 | public function asJson(): Client | 53 | public function asJson(): Client |
| 46 | { | 54 | { |
| 47 | - $this->requestOption = RequestOptions::JSON; | ||
| 48 | - | ||
| 49 | - return $this; | 55 | + return new Client( |
| 56 | + $this->app, | ||
| 57 | + RequestOptions::JSON, | ||
| 58 | + $this->withSession | ||
| 59 | + ); | ||
| 50 | } | 60 | } |
| 51 | 61 | ||
| 52 | public function asMultipart(): Client | 62 | public function asMultipart(): Client |
| 53 | { | 63 | { |
| 54 | - $this->requestOption = RequestOptions::MULTIPART; | ||
| 55 | - | ||
| 56 | - return $this; | 64 | + return new Client( |
| 65 | + $this->app, | ||
| 66 | + RequestOptions::MULTIPART, | ||
| 67 | + $this->withSession | ||
| 68 | + ); | ||
| 57 | } | 69 | } |
| 58 | 70 | ||
| 59 | public function withSession(): Client | 71 | public function withSession(): Client |
| 60 | { | 72 | { |
| 61 | - $this->withSession = true; | ||
| 62 | - | ||
| 63 | - return $this; | 73 | + return new Client( |
| 74 | + $this->app, | ||
| 75 | + $this->requestOption, | ||
| 76 | + true | ||
| 77 | + ); | ||
| 64 | } | 78 | } |
| 65 | 79 | ||
| 66 | public function refresh() | 80 | public function refresh() |
-
请 注册 或 登录 后发表评论