class ClientFactory in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Http/ClientFactory.php \Drupal\Core\Http\ClientFactory
Helper class to construct a HTTP client with Drupal specific config.
Hierarchy
- class \Drupal\Core\Http\ClientFactory
Expanded class hierarchy of ClientFactory
2 files declare their use of ClientFactory
- ClientFactoryTest.php in core/
tests/ Drupal/ Tests/ Core/ Http/ ClientFactoryTest.php - Contains \Drupal\Tests\Core\Http\ClientFactoryTest.
- DefaultFetcher.php in core/
modules/ aggregator/ src/ Plugin/ aggregator/ fetcher/ DefaultFetcher.php - Contains \Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher.
1 string reference to 'ClientFactory'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ClientFactory
File
- core/
lib/ Drupal/ Core/ Http/ ClientFactory.php, line 18 - Contains \Drupal\Core\Http\ClientFactory.
Namespace
Drupal\Core\HttpView source
class ClientFactory {
/**
* The handler stack.
*
* @var \GuzzleHttp\HandlerStack
*/
protected $stack;
/**
* Constructs a new ClientFactory instance.
*
* @param \GuzzleHttp\HandlerStack $stack
* The handler stack.
*/
public function __construct(HandlerStack $stack) {
$this->stack = $stack;
}
/**
* Constructs a new client object from some configuration.
*
* @param array $config
* The config for the client.
*
* @return \GuzzleHttp\Client
* The HTTP client.
*/
public function fromOptions(array $config = []) {
$default_config = [
// Security consideration: we must not use the certificate authority
// file shipped with Guzzle because it can easily get outdated if a
// certificate authority is hacked. Instead, we rely on the certificate
// authority file provided by the operating system which is more likely
// going to be updated in a timely fashion. This overrides the default
// path to the pem file bundled with Guzzle.
'verify' => TRUE,
'timeout' => 30,
'headers' => [
'User-Agent' => 'Drupal/' . \Drupal::VERSION . ' (+https://www.drupal.org/) ' . \GuzzleHttp\default_user_agent(),
],
'handler' => $this->stack,
];
$config = NestedArray::mergeDeep($default_config, Settings::get('http_client_config', []), $config);
return new Client($config);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientFactory:: |
protected | property | The handler stack. | |
ClientFactory:: |
public | function | Constructs a new client object from some configuration. | |
ClientFactory:: |
public | function | Constructs a new ClientFactory instance. |