class HttpClientMiddleware in Devel 4.x
Same name and namespace in other branches
- 8.3 webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware
- 8 webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware
- 8.2 webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware
Class HttpClientMiddleware.
Hierarchy
- class \Drupal\webprofiler\Http\HttpClientMiddleware
Expanded class hierarchy of HttpClientMiddleware
1 file declares its use of HttpClientMiddleware
- HttpDataCollector.php in webprofiler/
src/ DataCollector/ HttpDataCollector.php
1 string reference to 'HttpClientMiddleware'
- webprofiler.services.yml in webprofiler/
webprofiler.services.yml - webprofiler/webprofiler.services.yml
1 service uses HttpClientMiddleware
File
- webprofiler/
src/ Http/ HttpClientMiddleware.php, line 12
Namespace
Drupal\webprofiler\HttpView source
class HttpClientMiddleware {
/**
* @var array
*/
private $completedRequests;
/**
* @var array
*/
private $failedRequests;
/**
*
*/
public function __construct() {
$this->completedRequests = [];
$this->failedRequests = [];
}
/**
* {@inheritdoc}
*/
public function __invoke() {
return function ($handler) {
return function (RequestInterface $request, array $options) use ($handler) {
// If on_stats callback is already set then save it
// and call it after ours.
if (isset($options['on_stats'])) {
$next = $options['on_stats'];
}
else {
$next = function (TransferStats $stats) {
};
}
$options['on_stats'] = function (TransferStats $stats) use ($request, $next) {
$request->stats = $stats;
$next($stats);
};
return $handler($request, $options)
->then(function ($response) use ($request) {
$this->completedRequests[] = [
'request' => $request,
'response' => $response,
];
return $response;
}, function ($reason) use ($request) {
$response = $reason instanceof RequestException ? $reason
->getResponse() : NULL;
$this->failedRequests[] = [
'request' => $request,
'response' => $response,
'message' => $reason
->getMessage(),
];
return \GuzzleHttp\Promise\rejection_for($reason);
});
};
};
}
/**
* @return array
*/
public function getCompletedRequests() {
return $this->completedRequests;
}
/**
* @return array
*/
public function getFailedRequests() {
return $this->failedRequests;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HttpClientMiddleware:: |
private | property | ||
HttpClientMiddleware:: |
private | property | ||
HttpClientMiddleware:: |
public | function | ||
HttpClientMiddleware:: |
public | function | ||
HttpClientMiddleware:: |
public | function | ||
HttpClientMiddleware:: |
public | function |