Skip to content

Commit 101ece1

Browse files
Use native JSON functions in documentation (#97)
1 parent b011d04 commit 101ece1

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use GuzzleHttp\Command\Result;
3636
use GuzzleHttp\Command\ResultInterface;
3737
use GuzzleHttp\Command\ServiceClient;
3838
use GuzzleHttp\Psr7\Request;
39-
use GuzzleHttp\Utils;
4039
use Psr\Http\Message\RequestInterface;
4140
use Psr\Http\Message\ResponseInterface;
4241

@@ -47,15 +46,15 @@ $client = new ServiceClient(
4746
'POST',
4847
'/' . rawurlencode($command->getName()),
4948
['Content-Type' => 'application/json'],
50-
Utils::jsonEncode($command->toArray())
49+
\json_encode($command->toArray(), \JSON_THROW_ON_ERROR)
5150
);
5251
},
5352
function (
5453
ResponseInterface $response,
5554
RequestInterface $request,
5655
CommandInterface $command
5756
): ResultInterface {
58-
return new Result(Utils::jsonDecode((string) $response->getBody(), true));
57+
return new Result(\json_decode((string) $response->getBody(), true, 512, \JSON_THROW_ON_ERROR));
5958
}
6059
);
6160

‎docs/service-clients.md‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use GuzzleHttp\Command\Result;
6767
use GuzzleHttp\Command\ResultInterface;
6868
use GuzzleHttp\Command\ServiceClient;
6969
use GuzzleHttp\Psr7\Request;
70-
use GuzzleHttp\Utils;
7170
use Psr\Http\Message\RequestInterface;
7271
use Psr\Http\Message\ResponseInterface;
7372

@@ -78,7 +77,7 @@ $client = new ServiceClient(
7877
'POST',
7978
'/' . rawurlencode($command->getName()),
8079
['Accept' => 'application/json', 'Content-Type' => 'application/json'],
81-
Utils::jsonEncode($command->toArray())
80+
\json_encode($command->toArray(), \JSON_THROW_ON_ERROR)
8281
);
8382
},
8483
function (
@@ -87,7 +86,7 @@ $client = new ServiceClient(
8786
CommandInterface $command
8887
): ResultInterface {
8988
return new Result(
90-
Utils::jsonDecode((string) $response->getBody(), true)
89+
\json_decode((string) $response->getBody(), true, 512, \JSON_THROW_ON_ERROR)
9190
);
9291
}
9392
);
@@ -102,11 +101,10 @@ parameters:
102101
```php
103102
use GuzzleHttp\Command\CommandInterface;
104103
use GuzzleHttp\Psr7\Request;
105-
use GuzzleHttp\Utils;
106104
use Psr\Http\Message\RequestInterface;
107105

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

112110
return new Request(
@@ -125,7 +123,6 @@ shape. It receives the response, request, and original command:
125123
use GuzzleHttp\Command\CommandInterface;
126124
use GuzzleHttp\Command\Result;
127125
use GuzzleHttp\Command\ResultInterface;
128-
use GuzzleHttp\Utils;
129126
use Psr\Http\Message\RequestInterface;
130127
use Psr\Http\Message\ResponseInterface;
131128

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

0 commit comments

Comments
 (0)