Debian Codegraph @

lib/3rdParty/composer/symfony/http-client/AsyncDecoratorTrait.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\HttpClient;
13
14 use Symfony\Component\HttpClient\Response\AsyncResponse;
15 use Symfony\Component\HttpClient\Response\ResponseStream;
16 use Symfony\Contracts\HttpClient\ResponseInterface;
17 use Symfony\Contracts\HttpClient\ResponseStreamInterface;
18
19 /**
20 * Eases with processing responses while streaming them.
21 *
22 * @author Nicolas Grekas <[email protected]>
23 */
24 trait AsyncDecoratorTrait
25 {
26 use DecoratorTrait;
27
28 /**
29 * @return AsyncResponse
30 */
31 abstract public function request(string $method, string $url, array $options = []): ResponseInterface;
32
33 public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface
34 {
35 if ($responses instanceof AsyncResponse) {
36 $responses = [$responses];
37 }
38
39 return new ResponseStream(AsyncResponse::stream($responses, $timeout, static::class));
40 }
41 }