chillerlan /
php-httpinterface
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class CurlMultiHandle |
||
| 4 | * |
||
| 5 | * @created 03.11.2020 |
||
| 6 | * @author smiley <[email protected]> |
||
| 7 | * @copyright 2020 smiley |
||
| 8 | * @license MIT |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace chillerlan\HTTP\CurlUtils; |
||
| 12 | |||
| 13 | use chillerlan\Settings\SettingsContainerInterface; |
||
| 14 | use Psr\Http\Message\{RequestInterface, ResponseInterface}; |
||
| 15 | |||
| 16 | class CurlMultiHandle extends CurlHandle{ |
||
| 17 | |||
| 18 | protected MultiResponseHandlerInterface $multiResponseHandler; |
||
| 19 | |||
| 20 | public function __construct( |
||
| 21 | MultiResponseHandlerInterface $multiResponseHandler, |
||
| 22 | RequestInterface $request, |
||
| 23 | ResponseInterface $response, |
||
| 24 | SettingsContainerInterface $options |
||
| 25 | ){ |
||
| 26 | parent::__construct($request, $response, $options); |
||
| 27 | |||
| 28 | $this->multiResponseHandler = $multiResponseHandler; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * a handle ID (counter), used in CurlMultiClient |
||
| 33 | */ |
||
| 34 | protected ?int $id = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * a retry counter, used in CurlMultiClient |
||
| 38 | */ |
||
| 39 | protected int $retries = 0; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * |
||
| 43 | */ |
||
| 44 | public function getID():?int{ |
||
| 45 | return $this->id; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * |
||
| 50 | */ |
||
| 51 | public function setID(int $id):CurlMultiHandle{ |
||
| 52 | $this->id = $id; |
||
| 53 | |||
| 54 | return $this; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * |
||
| 59 | */ |
||
| 60 | public function getRetries():int{ |
||
| 61 | return $this->retries; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * |
||
| 66 | */ |
||
| 67 | public function setRetries(int $retries):CurlMultiHandle{ |
||
| 68 | $this->retries = $retries; |
||
| 69 | |||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * |
||
| 75 | */ |
||
| 76 | public function addRetry():int{ |
||
| 77 | return ++$this->retries; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * |
||
| 82 | */ |
||
| 83 | public function handleResponse():?RequestInterface{ |
||
| 84 | $info = curl_getinfo($this->curl); |
||
| 85 | |||
| 86 | return $this->multiResponseHandler->handleResponse( |
||
| 87 | $this->response, |
||
| 88 | $this->request, |
||
| 89 | $this->id, |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 90 | (is_array($info) ? $info : []) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | } |
||
| 95 |