class HttpDataCollector in Devel 4.x
Same name and namespace in other branches
- 8.3 webprofiler/src/DataCollector/HttpDataCollector.php \Drupal\webprofiler\DataCollector\HttpDataCollector
- 8 webprofiler/src/DataCollector/HttpDataCollector.php \Drupal\webprofiler\DataCollector\HttpDataCollector
- 8.2 webprofiler/src/DataCollector/HttpDataCollector.php \Drupal\webprofiler\DataCollector\HttpDataCollector
Collects data about http calls during request.
Hierarchy
- class \Drupal\webprofiler\DataCollector\HttpDataCollector extends \Symfony\Component\HttpKernel\DataCollector\DataCollector implements DrupalDataCollectorInterface uses StringTranslationTrait
Expanded class hierarchy of HttpDataCollector
1 string reference to 'HttpDataCollector'
- webprofiler.services.yml in webprofiler/
webprofiler.services.yml - webprofiler/webprofiler.services.yml
1 service uses HttpDataCollector
File
- webprofiler/
src/ DataCollector/ HttpDataCollector.php, line 15
Namespace
Drupal\webprofiler\DataCollectorView source
class HttpDataCollector extends DataCollector implements DrupalDataCollectorInterface {
use StringTranslationTrait, DrupalDataCollectorTrait;
/**
* @var \GuzzleHttp\Client
*/
private $middleware;
/**
* @param \Drupal\webprofiler\Http\HttpClientMiddleware $middleware
*/
public function __construct(HttpClientMiddleware $middleware) {
$this->middleware = $middleware;
$this->data['completed'] = [];
$this->data['failed'] = [];
}
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL) {
$completed = $this->middleware
->getCompletedRequests();
$failed = $this->middleware
->getFailedRequests();
foreach ($completed as $data) {
/** @var \GuzzleHttp\Psr7\Request $request */
$request = $data['request'];
/** @var \GuzzleHttp\Psr7\Response $response */
$response = $data['response'];
/** @var \GuzzleHttp\TransferStats $stats */
$stats = $request->stats;
$uri = $request
->getUri();
$this->data['completed'][] = [
'request' => [
'method' => $request
->getMethod(),
'uri' => [
'schema' => $uri
->getScheme(),
'host' => $uri
->getHost(),
'port' => $uri
->getPort(),
'path' => $uri
->getPath(),
'query' => $uri
->getQuery(),
'fragment' => $uri
->getFragment(),
],
'headers' => $request
->getHeaders(),
'protocol' => $request
->getProtocolVersion(),
'request_target' => $request
->getRequestTarget(),
'stats' => [
'transferTime' => $stats
->getTransferTime(),
'handlerStats' => $stats
->getHandlerStats(),
],
],
'response' => [
'phrase' => $response
->getReasonPhrase(),
'status' => $response
->getStatusCode(),
'headers' => $response
->getHeaders(),
'protocol' => $response
->getProtocolVersion(),
],
];
}
foreach ($failed as $data) {
/** @var \GuzzleHttp\Psr7\Request $request */
$request = $data['request'];
/** @var \GuzzleHttp\Psr7\Response $response */
$response = $data['response'];
$uri = $request
->getUri();
$failureData = [
'request' => [
'method' => $request
->getMethod(),
'uri' => [
'schema' => $uri
->getScheme(),
'host' => $uri
->getHost(),
'port' => $uri
->getPort(),
'path' => $uri
->getPath(),
'query' => $uri
->getQuery(),
'fragment' => $uri
->getFragment(),
],
'headers' => $request
->getHeaders(),
'protocol' => $request
->getProtocolVersion(),
'request_target' => $request
->getRequestTarget(),
],
];
if ($response) {
$failureData['response'] = [
'phrase' => $response
->getReasonPhrase(),
'status' => $response
->getStatusCode(),
'headers' => $response
->getHeaders(),
'protocol' => $response
->getProtocolVersion(),
];
}
$this->data['failed'][] = $failureData;
}
}
/**
* @return int
*/
public function getCompletedRequestsCount() {
return count($this
->getCompletedRequests());
}
/**
* @return array
*/
public function getCompletedRequests() {
return $this->data['completed'];
}
/**
* @return int
*/
public function getFailedRequestsCount() {
return count($this
->getFailedRequests());
}
/**
* @return array
*/
public function getFailedRequests() {
return $this->data['failed'];
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'http';
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this
->t('Http');
}
/**
* {@inheritdoc}
*/
public function getPanelSummary() {
return $this
->t('Completed @completed, error @error', [
'@completed' => $this
->getCompletedRequestsCount(),
'@error' => $this
->getFailedRequestsCount(),
]);
}
/**
* {@inheritdoc}
*/
public function getIcon() {
return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAATlJREFUeNrsleERgjAMha0TdISOwAZ2BEZghI7ABo7AOQFuwAjoBLgBblBbfb0LudByp/4jdw+PNnxtkqYq7/3h13Y8/MF26B9spfo6yAX1QSa6EY2Y0xLrzROgddAMOcgLmuFbhDqyG00W8Rm1JWgEWCG0oQBuJKjGigNUs/xWUJdJheZQJzhZFGkgKWkw1mM8bmTCvOPQcSVXrTA+Ydc0kujXJGg6p5VwrG5BJzb2CLriN9kT74afUylPloQ+kdDPELXpg1qGvwbtURwjFGkkC8RIZw6d2QeO7MII81wRbDm0Z068Zf0G1bxQl8z1UH1zoQwk9NRZdkPoHt+KbZoqa+HYZS4T3iimdEvRDrIF4KIRclBNjk+uSB2/eBJUvR9KSek26BZHOit2zl3oqkV91P6//3N7CTAAIIc/qj2gy4gAAAAASUVORK5CYII=';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDataCollectorInterface:: |
public | function | 8 | |
DrupalDataCollectorInterface:: |
public | function | 1 | |
DrupalDataCollectorInterface:: |
public | function | Returns the libraries needed in detail panel. | 2 |
DrupalDataCollectorInterface:: |
public | function | Returns true if this datacollector has a detail panel. | 2 |
HttpDataCollector:: |
private | property | ||
HttpDataCollector:: |
public | function | ||
HttpDataCollector:: |
public | function | ||
HttpDataCollector:: |
public | function | ||
HttpDataCollector:: |
public | function | ||
HttpDataCollector:: |
public | function | ||
HttpDataCollector:: |
public | function |
Returns the collector icon in base64 format. Overrides DrupalDataCollectorInterface:: |
|
HttpDataCollector:: |
public | function |
Returns the name of the collector. Overrides DrupalDataCollectorInterface:: |
|
HttpDataCollector:: |
public | function |
Returns the string used in vertical tab summary. Overrides DrupalDataCollectorInterface:: |
|
HttpDataCollector:: |
public | function |
Returns the datacollector title. Overrides DrupalDataCollectorInterface:: |
|
HttpDataCollector:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |