Skip to content

Commit 80a6915

Browse files
author
Antoine Aflalo
committed
fix(EmptyRequest): Don't have a body for GET requests
Don't serialize STATIC properties of requests.
1 parent ebbef37 commit 80a6915

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/Client/OAuthClient.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,6 @@ public function processRequest(IRequest $request): IResponse
274274
$options[RequestOptions::HEADERS] = $headers;
275275
}
276276

277-
if (isset($options[RequestOptions::JSON]) && empty($options[RequestOptions::JSON])) {
278-
unset($options[RequestOptions::JSON]);
279-
}
280-
281277
try {
282278
$response = $this->guzzleClient->request($request->httpType()->getValue(), $request->toUri(), $options);
283279
$parsedData = JSONParsing::responseToJson($response);

src/Request/Api/BaseRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ final public function requestType(): RequestType
198198
*/
199199
public function requestOptions(): array
200200
{
201+
/**
202+
* Don't set any JSON if it's a get request
203+
*/
204+
if ($this->requestType()->is(RequestType::HTTP_GET())) {
205+
return [];
206+
}
201207
$options = [
202208
RequestOptions::JSON => $this->toArray(),
203209
];

src/Utils/Reflection/ReflectionUtil.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ public static function getAllProperties($class, $blacklist = [])
142142
return $properties;
143143
}
144144

145-
return array_filter($properties, function (\ReflectionProperty $property) use ($blacklist) {
146-
return !in_array($property->name, $blacklist);
147-
});
145+
return array_filter(
146+
$properties,
147+
function (\ReflectionProperty $property) use ($blacklist) {
148+
return !$property->isStatic() && !in_array($property->name, $blacklist);
149+
}
150+
);
148151
}
149152

150153
/**

tests/src/Base/Request/NullableTestRequest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use ZEROSPAM\Framework\SDK\Request\Api\HasNullableFields;
1212
use ZEROSPAM\Framework\SDK\Request\Api\WithNullableFields;
13+
use ZEROSPAM\Framework\SDK\Request\Type\RequestType;
1314
use ZEROSPAM\Framework\SDK\Test\Base\Data\Request\TestRequest;
1415

1516
class NullableTestRequest extends TestRequest implements WithNullableFields
@@ -32,4 +33,15 @@ public function setNullField(?string $nullField)
3233

3334
return $this;
3435
}
36+
37+
/**
38+
* Type of request.
39+
*
40+
* @return RequestType
41+
*/
42+
public function httpType(): RequestType
43+
{
44+
return RequestType::HTTP_POST();
45+
}
46+
3547
}

0 commit comments

Comments
 (0)