1
0
mirror of https://github.com/halaxa/json-machine.git synced 2025-07-16 03:56:23 +02:00
Files
json-machine/examples/symfonyHttpClient.php
2022-01-27 20:22:36 +01:00

22 lines
632 B
PHP

<?php
use JsonMachine\Items;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
require_once __DIR__ . '/../../vendor/autoload.php';
function httpClientChunks(ResponseStreamInterface $responseStream)
{
foreach ($responseStream as $chunk) {
yield $chunk->getContent();
}
}
$client = HttpClient::create();
$response = $client->request('GET', 'https://httpbin.org/anything?key=value');
$jsonChunks = httpClientChunks($client->stream($response));
foreach (Items::fromIterable($jsonChunks, ['pointer' => '/args']) as $key => $value) {
var_dump($key, $value);
}