class LockrClient in Lockr 7.3
Hierarchy
- class \Lockr\LockrClient
Expanded class hierarchy of LockrClient
1 file declares its use of LockrClient
- lockr.module in ./
lockr.module - Hook implementations and callbacks for lockr.
File
- vendor/
lockr/ lockr/ src/ LockrClient.php, line 9
Namespace
LockrView source
class LockrClient {
const VERSION = '1.0.8';
/** @var GuzzleHttp\ClientInterface $httpClient */
private $httpClient;
/** @var LockrStatsInterface $stats */
private $stats;
/** @var bool $hasCert */
private $hasCert = false;
/**
* @param GuzzleHttp\ClientInterface $http_client
*/
public function __construct(GuzzleHttp\ClientInterface $http_client, LockrStatsInterface $stats = null) {
$this->httpClient = $http_client;
$this->stats = $stats ?: new BlackholeStats();
$this->hasCert = (bool) $http_client
->getConfig('cert');
}
/**
* Whether the request will have a client cert attached.
*
* @return bool
*/
public function hasCert() {
return $this->hasCert;
}
/**
* Gets the underlying HTTP client.
*
* @return GuzzleHttp\ClientInterface
*/
public function getHttpClient() {
return $this->httpClient;
}
/**
* Returns the stats handler.
*
* @return LockrStatsInterface
*/
public function getStats() {
return $this->stats;
}
/**
* @param SettingsInterface $settings
*/
public static function createFromSettings(SettingsInterface $settings) {
$ua = 'php/' . phpversion() . ' LockrClient/' . self::VERSION;
$base_options = [
'base_uri' => "https://{$settings->getHostname()}",
'connect_timeout' => 2.0,
'expect' => false,
'headers' => [
'accept' => [
'application/json',
],
'user-agent' => [
$ua,
],
],
'http_errors' => false,
'read_timeout' => 3.0,
'timeout' => 5.0,
];
$options = array_replace($base_options, $settings
->getOptions());
$client = new GuzzleHttp\Client($options);
return new static($client);
}
/**
* @param array $data
*
* @return array
*/
public function query(array $data) {
$resp = $this->httpClient
->request('POST', '/graphql', [
'json' => $data,
]);
$resp_data = json_decode((string) $resp
->getBody(), true);
if (!empty($resp_data['errors'])) {
throw new LockrApiException($resp_data['errors']);
}
return $resp_data['data'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LockrClient:: |
private | property | @var bool $hasCert | |
LockrClient:: |
private | property | @var GuzzleHttp\ClientInterface $httpClient | |
LockrClient:: |
private | property | @var LockrStatsInterface $stats | |
LockrClient:: |
public static | function | ||
LockrClient:: |
public | function | Gets the underlying HTTP client. | |
LockrClient:: |
public | function | Returns the stats handler. | |
LockrClient:: |
public | function | Whether the request will have a client cert attached. | |
LockrClient:: |
public | function | ||
LockrClient:: |
constant | |||
LockrClient:: |
public | function |