symfonyHttpClient.php 656 B

1234567891011121314151617181920212223
  1. <?php
  2. declare(strict_types=1);
  3. use JsonMachine\Items;
  4. use Symfony\Component\HttpClient\HttpClient;
  5. use Symfony\Contracts\HttpClient\ResponseStreamInterface;
  6. require_once __DIR__.'/../../vendor/autoload.php';
  7. function httpClientChunks(ResponseStreamInterface $responseStream)
  8. {
  9. foreach ($responseStream as $chunk) {
  10. yield $chunk->getContent();
  11. }
  12. }
  13. $client = HttpClient::create();
  14. $response = $client->request('GET', 'https://httpbin.org/anything?key=value');
  15. $jsonChunks = httpClientChunks($client->stream($response));
  16. foreach (Items::fromIterable($jsonChunks, ['pointer' => '/args']) as $key => $value) {
  17. var_dump($key, $value);
  18. }