作者 lackoxygen

fix:属性污染

... ... @@ -18,13 +18,19 @@ class Client extends ServiceManager
private string $requestOption = '';
private bool $withSession = false;
private bool $withSession;
public function __construct(Application $app)
public function __construct(
Application $app, $requestOption = '', $withSession = false
)
{
parent::__construct($app);
$this->listen();
$this->requestOption = $requestOption;
$this->withSession = $withSession;
}
protected function listen()
... ... @@ -37,30 +43,38 @@ class Client extends ServiceManager
public function asForm(): Client
{
$this->requestOption = RequestOptions::FORM_PARAMS;
return $this;
return new Client(
$this->app,
RequestOptions::FORM_PARAMS,
$this->withSession
);
}
public function asJson(): Client
{
$this->requestOption = RequestOptions::JSON;
return $this;
return new Client(
$this->app,
RequestOptions::JSON,
$this->withSession
);
}
public function asMultipart(): Client
{
$this->requestOption = RequestOptions::MULTIPART;
return $this;
return new Client(
$this->app,
RequestOptions::MULTIPART,
$this->withSession
);
}
public function withSession(): Client
{
$this->withSession = true;
return $this;
return new Client(
$this->app,
$this->requestOption,
true
);
}
public function refresh()
... ...