HttpClientTrait.php in Markdown 8.2
File
src/Traits/HttpClientTrait.php
View source
<?php
namespace Drupal\markdown\Traits;
trait HttpClientTrait {
protected static $httpClient;
protected static function httpClient($name = 'markdown', $type = 'module') {
if (!static::$httpClient) {
$info = system_get_info($type, $name);
$extension = isset($info['name']) ? $info['name'] : $name;
if ($info && !empty($info['version'])) {
$extension .= '/' . $info['version'];
}
$extension .= " (+https://www.drupal.org/project/{$name})";
$httpClientFactory = \Drupal::service('http_client_factory');
static::$httpClient = $httpClientFactory
->fromOptions([
'headers' => [
'User-Agent' => $extension . ' Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
],
]);
}
return static::$httpClient;
}
}
Traits
Name |
Description |
HttpClientTrait |
Trait to assist with creating an HTTP client using module info as user-agent. |