ApiClient.php in Auth0 Single Sign On 8.2
File
vendor/auth0/auth0-php/src/API/Helpers/ApiClient.php
View source
<?php
namespace Auth0\SDK\API\Helpers;
use Auth0\SDK\API\Header\ContentType;
use Auth0\SDK\API\Header\Telemetry;
class ApiClient {
const API_VERSION = '5.7.0';
protected static $infoHeadersDataEnabled = true;
protected static $infoHeadersData;
public static function setInfoHeadersData(InformationHeaders $infoHeadersData) {
if (!self::$infoHeadersDataEnabled) {
return null;
}
self::$infoHeadersData = $infoHeadersData;
}
public static function getInfoHeadersData() {
if (!self::$infoHeadersDataEnabled) {
return null;
}
if (self::$infoHeadersData === null) {
self::$infoHeadersData = new InformationHeaders();
self::$infoHeadersData
->setCorePackage();
}
return self::$infoHeadersData;
}
public static function disableInfoHeaders() {
self::$infoHeadersDataEnabled = false;
}
protected $domain;
protected $basePath;
protected $headers;
protected $guzzleOptions;
protected $returnType;
public function __construct($config) {
$this->basePath = $config['basePath'];
$this->domain = $config['domain'];
$this->returnType = isset($config['returnType']) ? $config['returnType'] : null;
$this->headers = isset($config['headers']) ? $config['headers'] : [];
$this->guzzleOptions = isset($config['guzzleOptions']) ? $config['guzzleOptions'] : [];
if (self::$infoHeadersDataEnabled) {
$this->headers[] = new Telemetry(self::getInfoHeadersData()
->build());
}
}
public function __call($name, $arguments) {
$builder = new RequestBuilder([
'domain' => $this->domain,
'basePath' => $this->basePath,
'method' => $name,
'guzzleOptions' => $this->guzzleOptions,
'returnType' => $this->returnType,
]);
return $builder
->withHeaders($this->headers);
}
public function method($method, $set_content_type = true) {
$method = strtolower($method);
$builder = new RequestBuilder([
'domain' => $this->domain,
'basePath' => $this->basePath,
'method' => $method,
'guzzleOptions' => $this->guzzleOptions,
'returnType' => $this->returnType,
]);
$builder
->withHeaders($this->headers);
if ($set_content_type && in_array($method, [
'patch',
'post',
'put',
'delete',
])) {
$builder
->withHeader(new ContentType('application/json'));
}
return $builder;
}
}