@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | \curl_setopt($ch, \CURLOPT_PRIVATE, \in_array($method, ['GET', 'HEAD', 'OPTIONS', 'TRACE'], true) && 1.0 < (float) ($options['http_version'] ?? 1.1) ? 'H2' : 'H0'); // H = headers + retry counter |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - \curl_setopt($ch, \CURLOPT_HEADERFUNCTION, static function ($ch, string $data) use (&$info, &$headers, $options, $multi, $id, &$location, $resolveRedirect, $logger): int { |
|
| 78 | + \curl_setopt($ch, \CURLOPT_HEADERFUNCTION, static function($ch, string $data) use (&$info, &$headers, $options, $multi, $id, &$location, $resolveRedirect, $logger): int { |
|
| 79 | 79 | if (0 !== substr_compare($data, "\r\n", -2)) { |
| 80 | 80 | return 0; |
| 81 | 81 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | if (null === $options) { |
| 93 | 93 | // Pushed response: buffer until requested |
| 94 | - \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int { |
|
| 94 | + \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function($ch, string $data) use ($multi, $id): int { |
|
| 95 | 95 | $multi->handlesActivity[$id][] = $data; |
| 96 | 96 | curl_pause($ch, \CURLPAUSE_RECV); |
| 97 | 97 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $execCounter = $multi->execCounter; |
| 105 | - $this->info['pause_handler'] = static function (float $duration) use ($ch, $multi, $execCounter) { |
|
| 105 | + $this->info['pause_handler'] = static function(float $duration) use ($ch, $multi, $execCounter) { |
|
| 106 | 106 | if (0 < $duration) { |
| 107 | 107 | if ($execCounter === $multi->execCounter) { |
| 108 | 108 | $multi->execCounter = !\is_float($execCounter) ? 1 + $execCounter : \PHP_INT_MIN; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | if ($onProgress = $options['on_progress']) { |
| 129 | 129 | $url = isset($info['url']) ? ['url' => $info['url']] : []; |
| 130 | 130 | \curl_setopt($ch, \CURLOPT_NOPROGRESS, false); |
| 131 | - \curl_setopt($ch, \CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi, $debugBuffer) { |
|
| 131 | + \curl_setopt($ch, \CURLOPT_PROGRESSFUNCTION, static function($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi, $debugBuffer) { |
|
| 132 | 132 | try { |
| 133 | 133 | rewind($debugBuffer); |
| 134 | 134 | $debug = ['debug' => stream_get_contents($debugBuffer)]; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | }); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int { |
|
| 147 | + \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function($ch, string $data) use ($multi, $id): int { |
|
| 148 | 148 | if ('H' === (\curl_getinfo($ch, \CURLINFO_PRIVATE)[0] ?? null)) { |
| 149 | 149 | $multi->handlesActivity[$id][] = null; |
| 150 | 150 | $multi->handlesActivity[$id][] = new TransportException(\sprintf('Unsupported protocol for "%s"', \curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL))); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | return 0; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function ($ch, string $data) use ($multi, $id): int { |
|
| 155 | + \curl_setopt($ch, \CURLOPT_WRITEFUNCTION, static function($ch, string $data) use ($multi, $id): int { |
|
| 156 | 156 | $multi->handlesActivity[$id][] = $data; |
| 157 | 157 | |
| 158 | 158 | return \strlen($data); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | return \strlen($data); |
| 164 | 164 | }); |
| 165 | 165 | |
| 166 | - $this->initializer = static function (self $response) { |
|
| 166 | + $this->initializer = static function(self $response) { |
|
| 167 | 167 | $waitFor = \curl_getinfo($ch = $response->handle, \CURLINFO_PRIVATE); |
| 168 | 168 | |
| 169 | 169 | return 'H' === $waitFor[0]; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $multi->openHandles[$id] = [$ch, $options]; |
| 174 | 174 | curl_multi_add_handle($multi->handle, $ch); |
| 175 | 175 | |
| 176 | - $this->canary = new Canary(static function () use ($ch, $multi, $id) { |
|
| 176 | + $this->canary = new Canary(static function() use ($ch, $multi, $id) { |
|
| 177 | 177 | unset($multi->pauseExpiries[$id], $multi->openHandles[$id], $multi->handlesActivity[$id]); |
| 178 | 178 | \curl_setopt($ch, \CURLOPT_PRIVATE, '_0'); |
| 179 | 179 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $response->requestOptions = $options; |
| 127 | 127 | $response->id = ++self::$idSequence; |
| 128 | 128 | $response->shouldBuffer = $options['buffer'] ?? true; |
| 129 | - $response->initializer = static function (self $response) { |
|
| 129 | + $response->initializer = static function(self $response) { |
|
| 130 | 130 | return \is_array($response->body[0] ?? null); |
| 131 | 131 | }; |
| 132 | 132 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | private static function writeRequest(self $response, array $options, ResponseInterface $mock) |
| 226 | 226 | { |
| 227 | - $onProgress = $options['on_progress'] ?? static function () {}; |
|
| 227 | + $onProgress = $options['on_progress'] ?? static function() {}; |
|
| 228 | 228 | $response->info += $mock->getInfo() ?: []; |
| 229 | 229 | |
| 230 | 230 | // simulate "size_upload" if it is set |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | private static function readResponse(self $response, array $options, ResponseInterface $mock, int &$offset) |
| 269 | 269 | { |
| 270 | - $onProgress = $options['on_progress'] ?? static function () {}; |
|
| 270 | + $onProgress = $options['on_progress'] ?? static function() {}; |
|
| 271 | 271 | |
| 272 | 272 | // populate info related to headers |
| 273 | 273 | $info = $mock->getInfo() ?: []; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $request->setHeader('Accept-Encoding', 'gzip'); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $this->initializer = static function (self $response) { |
|
| 70 | + $this->initializer = static function(self $response) { |
|
| 71 | 71 | return null !== $response->options; |
| 72 | 72 | }; |
| 73 | 73 | |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | $info['user_data'] = $options['user_data']; |
| 90 | 90 | $info['debug'] = ''; |
| 91 | 91 | |
| 92 | - $onProgress = $options['on_progress'] ?? static function () {}; |
|
| 93 | - $onProgress = $this->onProgress = static function () use (&$info, $onProgress) { |
|
| 92 | + $onProgress = $options['on_progress'] ?? static function() {}; |
|
| 93 | + $onProgress = $this->onProgress = static function() use (&$info, $onProgress) { |
|
| 94 | 94 | $info['total_time'] = micro\time(true) - $info['start_time']; |
| 95 | 95 | $onProgress((int) $info['size_download'], ((int) (1 + $info['download_content_length']) ?: 1) - 1, (array) $info); |
| 96 | 96 | }; |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | $throttleWatcher = null; |
| 102 | 102 | |
| 103 | 103 | $this->id = $id = self::$nextId++; |
| 104 | - Loop::defer(static function () use ($request, $multi, &$id, &$info, &$headers, $canceller, &$options, $onProgress, &$handle, $logger, &$pause) { |
|
| 104 | + Loop::defer(static function() use ($request, $multi, &$id, &$info, &$headers, $canceller, &$options, $onProgress, &$handle, $logger, &$pause) { |
|
| 105 | 105 | return new Coroutine(self::generateResponse($request, $multi, $id, $info, $headers, $canceller, $options, $onProgress, $handle, $logger, $pause)); |
| 106 | 106 | }); |
| 107 | 107 | |
| 108 | - $info['pause_handler'] = static function (float $duration) use (&$throttleWatcher, &$pauseDeferred, &$pause) { |
|
| 108 | + $info['pause_handler'] = static function(float $duration) use (&$throttleWatcher, &$pauseDeferred, &$pause) { |
|
| 109 | 109 | if (null !== $throttleWatcher) { |
| 110 | 110 | Loop::cancel($throttleWatcher); |
| 111 | 111 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $pauseDeferred = new Deferred(); |
| 118 | 118 | $deferred->resolve(); |
| 119 | 119 | } else { |
| 120 | - $throttleWatcher = Loop::delay(ceil(1000 * $duration), static function () use (&$pauseDeferred) { |
|
| 120 | + $throttleWatcher = Loop::delay(ceil(1000 * $duration), static function() use (&$pauseDeferred) { |
|
| 121 | 121 | $deferred = $pauseDeferred; |
| 122 | 122 | $pauseDeferred = new Deferred(); |
| 123 | 123 | $deferred->resolve(); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $multi->openHandles[$id] = $id; |
| 129 | 129 | ++$multi->responseCount; |
| 130 | 130 | |
| 131 | - $this->canary = new Canary(static function () use ($canceller, $multi, $id) { |
|
| 131 | + $this->canary = new Canary(static function() use ($canceller, $multi, $id) { |
|
| 132 | 132 | $canceller->cancel(); |
| 133 | 133 | unset($multi->openHandles[$id], $multi->handlesActivity[$id]); |
| 134 | 134 | }); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | private static function select(ClientState $multi, float $timeout): int |
| 203 | 203 | { |
| 204 | 204 | $timeout += micro\time(true); |
| 205 | - self::$delay = Loop::defer(static function () use ($timeout) { |
|
| 205 | + self::$delay = Loop::defer(static function() use ($timeout) { |
|
| 206 | 206 | if (0 < $timeout -= micro\time(true)) { |
| 207 | 207 | self::$delay = Loop::delay(ceil(1000 * $timeout), [Loop::class, 'stop']); |
| 208 | 208 | } else { |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | private static function generateResponse(Request $request, AmpClientState $multi, string $id, array &$info, array &$headers, CancellationTokenSource $canceller, array &$options, \Closure $onProgress, &$handle, ?LoggerInterface $logger, Promise &$pause) |
| 219 | 219 | { |
| 220 | - $request->setInformationalResponseHandler(static function (Response $response) use ($multi, $id, &$info, &$headers) { |
|
| 220 | + $request->setInformationalResponseHandler(static function(Response $response) use ($multi, $id, &$info, &$headers) { |
|
| 221 | 221 | self::addResponseHeaders($response, $info, $headers); |
| 222 | 222 | $multi->handlesActivity[$id][] = new InformationalChunk($response->getStatus(), $response->getHeaders()); |
| 223 | 223 | self::stopLoop(); |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | return null; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return static function ($value) use ($callback) { |
|
| 76 | + return static function($value) use ($callback) { |
|
| 77 | 77 | return promise_for($callback($value)); |
| 78 | 78 | }; |
| 79 | 79 | } |
@@ -153,7 +153,7 @@ |
||
| 153 | 153 | $this->info['previous_info'][] = $this->response->getInfo(); |
| 154 | 154 | if (null !== $onProgress = $options['on_progress'] ?? null) { |
| 155 | 155 | $thisInfo = &$this->info; |
| 156 | - $options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use (&$thisInfo, $onProgress) { |
|
| 156 | + $options['on_progress'] = static function(int $dlNow, int $dlSize, array $info) use (&$thisInfo, $onProgress) { |
|
| 157 | 157 | $onProgress($dlNow, $dlSize, $thisInfo + $info); |
| 158 | 158 | }; |
| 159 | 159 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | public function __construct(?callable $clientConfigurator, int $maxHostConnections, int $maxPendingPushes, ?LoggerInterface &$logger) |
| 55 | 55 | { |
| 56 | - $this->clientConfigurator = $clientConfigurator ?? static function (PooledHttpClient $client) { |
|
| 56 | + $this->clientConfigurator = $clientConfigurator ?? static function(PooledHttpClient $client) { |
|
| 57 | 57 | return new InterceptedHttpClient($client, new RetryRequests(2)); |
| 58 | 58 | }; |
| 59 | 59 | $this->maxHostConnections = $maxHostConnections; |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $request->addEventListener(new AmpListener($info, $options['peer_fingerprint']['pin-sha256'] ?? [], $onProgress, $handle)); |
| 97 | - $request->setPushHandler(function ($request, $response) use ($options): Promise { |
|
| 97 | + $request->setPushHandler(function($request, $response) use ($options): Promise { |
|
| 98 | 98 | return $this->handlePush($request, $response, $options); |
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | ($request->hasHeader('content-length') ? new Success((int) $request->getHeader('content-length')) : $request->getBody()->getBodyLength()) |
| 102 | - ->onResolve(static function ($e, $bodySize) use (&$info) { |
|
| 102 | + ->onResolve(static function($e, $bodySize) use (&$info) { |
|
| 103 | 103 | if (null !== $bodySize && 0 <= $bodySize) { |
| 104 | 104 | $info['upload_content_length'] = ((1 + $info['upload_content_length']) ?? 1) - 1 + $bodySize; |
| 105 | 105 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | [$client, $connector] = $this->getClient($options); |
| 109 | 109 | $response = $client->request($request, $cancellation); |
| 110 | - $response->onResolve(static function ($e) use ($connector, &$handle) { |
|
| 110 | + $response->onResolve(static function($e) use ($connector, &$handle) { |
|
| 111 | 111 | if (null === $e) { |
| 112 | 112 | $handle = $connector->handle; |
| 113 | 113 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | public function connect(string $uri, ?ConnectContext $context = null, ?CancellationToken $token = null): Promise |
| 153 | 153 | { |
| 154 | 154 | $result = $this->connector->connect($this->uri ?? $uri, $context, $token); |
| 155 | - $result->onResolve(function ($e, $socket) { |
|
| 155 | + $result->onResolve(function($e, $socket) { |
|
| 156 | 156 | $this->handle = null !== $socket ? $socket->getResource() : false; |
| 157 | 157 | }); |
| 158 | 158 | |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | ($this->onProgress)(); |
| 79 | 79 | |
| 80 | 80 | $chunk = $this->doRead(); |
| 81 | - $chunk->onResolve(function ($e, $data) { |
|
| 81 | + $chunk->onResolve(function($e, $data) { |
|
| 82 | 82 | if (null !== $data) { |
| 83 | 83 | $this->uploaded = \strlen($data); |
| 84 | 84 | } else { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | 'auth_ntlm' => null, // array|string - an array containing the username as first value, and optionally the |
| 42 | 42 | // password as the second one; or string like username:password - enabling NTLM auth |
| 43 | 43 | 'extra' => [ |
| 44 | - 'curl' => [], // A list of extra curl options indexed by their corresponding CURLOPT_* |
|
| 44 | + 'curl' => [], // A list of extra curl options indexed by their corresponding CURLOPT_* |
|
| 45 | 45 | ], |
| 46 | 46 | ]; |
| 47 | 47 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - curl_multi_setopt($this->multi->handle, \CURLMOPT_PUSHFUNCTION, function ($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) { |
|
| 100 | + curl_multi_setopt($this->multi->handle, \CURLMOPT_PUSHFUNCTION, function($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) { |
|
| 101 | 101 | return $this->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes); |
| 102 | 102 | }); |
| 103 | 103 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } else { |
| 244 | 244 | $eof = false; |
| 245 | 245 | $buffer = ''; |
| 246 | - $curlopts[\CURLOPT_READFUNCTION] = static function ($ch, $fd, $length) use ($body, &$buffer, &$eof) { |
|
| 246 | + $curlopts[\CURLOPT_READFUNCTION] = static function($ch, $fd, $length) use ($body, &$buffer, &$eof) { |
|
| 247 | 247 | return self::readRequestBody($length, $body, $buffer, $eof); |
| 248 | 248 | }; |
| 249 | 249 | } |
@@ -473,18 +473,18 @@ discard block |
||
| 473 | 473 | $redirectHeaders = []; |
| 474 | 474 | if (0 < $options['max_redirects']) { |
| 475 | 475 | $redirectHeaders['host'] = $host; |
| 476 | - $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = \array_filter($options['headers'], static function ($h) { |
|
| 476 | + $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = \array_filter($options['headers'], static function($h) { |
|
| 477 | 477 | return 0 !== stripos($h, 'Host:'); |
| 478 | 478 | }); |
| 479 | 479 | |
| 480 | 480 | if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) { |
| 481 | - $redirectHeaders['no_auth'] = \array_filter($options['headers'], static function ($h) { |
|
| 481 | + $redirectHeaders['no_auth'] = \array_filter($options['headers'], static function($h) { |
|
| 482 | 482 | return 0 !== stripos($h, 'Authorization:') && 0 !== stripos($h, 'Cookie:'); |
| 483 | 483 | }); |
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - return static function ($ch, string $location) use ($redirectHeaders) { |
|
| 487 | + return static function($ch, string $location) use ($redirectHeaders) { |
|
| 488 | 488 | try { |
| 489 | 489 | $location = self::parseUrl($location); |
| 490 | 490 | } catch (InvalidArgumentException $e) { |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | |
| 505 | 505 | private function findConstantName($opt): ?string |
| 506 | 506 | { |
| 507 | - $constants = \array_filter(get_defined_constants(), static function ($v, $k) use ($opt) { |
|
| 507 | + $constants = \array_filter(get_defined_constants(), static function($v, $k) use ($opt) { |
|
| 508 | 508 | return $v === $opt && 'C' === $k[0] && (0 === \strpos($k, 'CURLOPT_') || 0 === \strpos($k, 'CURLINFO_')); |
| 509 | 509 | }, \ARRAY_FILTER_USE_BOTH); |
| 510 | 510 | |
@@ -136,7 +136,7 @@ |
||
| 136 | 136 | return new ResponseStream(MockResponse::stream($mockResponses, $timeout)); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - return new ResponseStream((function () use ($mockResponses, $clientResponses, $timeout) { |
|
| 139 | + return new ResponseStream((function() use ($mockResponses, $clientResponses, $timeout) { |
|
| 140 | 140 | yield from MockResponse::stream($mockResponses, $timeout); |
| 141 | 141 | yield $this->client->stream($clientResponses, $timeout); |
| 142 | 142 | })()); |