Skip to content

Commit cc37166

Browse files
authored
Update Clientable.php
1 parent 00b03fd commit cc37166

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Traits/Clientable.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22

3-
namespace ZhenMu\Support\Traits;
3+
/*
4+
* Fresns (https://fresns.org)
5+
* Copyright (C) 2021-Present Jarvis Tang
6+
*/
7+
8+
namespace Plugins\FresnsEngine;
49

510
trait Clientable
611
{
@@ -36,20 +41,19 @@ abstract public function getLastPage(): ?int;
3641

3742
abstract public function getDataList(): static|array|null;
3843

39-
protected function castResponse()
44+
public function castResponse()
4045
{
41-
$this->result = json_decode($content = $this->response->getBody()->getContents(), true) ?? [];
42-
$this->attributes = $this->result;
46+
$result = json_decode($content = $this->response->getBody()->getContents(), true) ?? [];
4347

44-
if (empty($this->result)) {
48+
if (empty($result)) {
4549
$this->handleEmptyResponse($content);
4650
}
4751

4852
if ($this->isErrorResponse()) {
4953
$this->handleErrorResponse($content);
5054
}
5155

52-
return true;
56+
return $result;
5357
}
5458

5559
public function paginate()
@@ -77,7 +81,9 @@ public function __call($method, $args)
7781
{
7882
$this->response = $this->getHttpClient()->$method(...$args);
7983

80-
$this->castResponse();
84+
$this->result = $this->castResponse();
85+
86+
$this->attributes = $this->result;
8187

8288
return $this;
8389
}

0 commit comments

Comments
 (0)