Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use GuzzleHttp\Command\Result;
use GuzzleHttp\Command\ResultInterface;
use GuzzleHttp\Command\ServiceClient;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -47,15 +46,15 @@ $client = new ServiceClient(
'POST',
'/' . rawurlencode($command->getName()),
['Content-Type' => 'application/json'],
Utils::jsonEncode($command->toArray())
\json_encode($command->toArray(), \JSON_THROW_ON_ERROR)
);
},
function (
ResponseInterface $response,
RequestInterface $request,
CommandInterface $command
): ResultInterface {
return new Result(Utils::jsonDecode((string) $response->getBody(), true));
return new Result(\json_decode((string) $response->getBody(), true, 512, \JSON_THROW_ON_ERROR));
}
);

Expand Down
11 changes: 4 additions & 7 deletions docs/service-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ use GuzzleHttp\Command\Result;
use GuzzleHttp\Command\ResultInterface;
use GuzzleHttp\Command\ServiceClient;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -78,7 +77,7 @@ $client = new ServiceClient(
'POST',
'/' . rawurlencode($command->getName()),
['Accept' => 'application/json', 'Content-Type' => 'application/json'],
Utils::jsonEncode($command->toArray())
\json_encode($command->toArray(), \JSON_THROW_ON_ERROR)
);
},
function (
Expand All @@ -87,7 +86,7 @@ $client = new ServiceClient(
CommandInterface $command
): ResultInterface {
return new Result(
Utils::jsonDecode((string) $response->getBody(), true)
\json_decode((string) $response->getBody(), true, 512, \JSON_THROW_ON_ERROR)
);
}
);
Expand All @@ -102,11 +101,10 @@ parameters:
```php
use GuzzleHttp\Command\CommandInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;

$commandToRequest = function (CommandInterface $command): RequestInterface {
$body = Utils::jsonEncode($command->toArray());
$body = \json_encode($command->toArray(), \JSON_THROW_ON_ERROR);
$path = '/commands/' . rawurlencode($command->getName());

return new Request(
Expand All @@ -125,7 +123,6 @@ shape. It receives the response, request, and original command:
use GuzzleHttp\Command\CommandInterface;
use GuzzleHttp\Command\Result;
use GuzzleHttp\Command\ResultInterface;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -137,7 +134,7 @@ $responseToResult = function (
return new Result([
'operation' => $command->getName(),
'statusCode' => $response->getStatusCode(),
'data' => Utils::jsonDecode((string) $response->getBody(), true),
'data' => \json_decode((string) $response->getBody(), true, 512, \JSON_THROW_ON_ERROR),
]);
};
```
Expand Down