Skip to content
Snippets Groups Projects

add dependency injection

1 file
+ 23
3
Compare changes
  • Side-by-side
  • Inline
@@ -9,6 +9,7 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
@@ -9,6 +9,7 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Url;
use Drupal\Core\Url;
use Drupal\Core\Http\ClientFactory;
use Drupal\Core\Http\ClientFactory;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\GuzzleException;
 
use Drupal\Component\Datetime\TimeInterface;
/**
/**
* Class Eloqua API Client Service.
* Class Eloqua API Client Service.
@@ -24,6 +25,14 @@ class EloquaApiClient {
@@ -24,6 +25,14 @@ class EloquaApiClient {
*/
*/
protected $loggerFactory;
protected $loggerFactory;
 
/**
 
* The time service.
 
*
 
* @var \Drupal\Component\Datetime\TimeInterface
 
*/
 
protected $time;
 
 
/**
/**
* Editable Tokens Config.
* Editable Tokens Config.
*
*
@@ -45,6 +54,13 @@ class EloquaApiClient {
@@ -45,6 +54,13 @@ class EloquaApiClient {
*/
*/
protected $httpClientFactory;
protected $httpClientFactory;
 
/**
 
* The cache backend property.
 
*
 
* @var \Drupal\Core\Cache\CacheBackendInterface
 
*/
 
protected $cacheBackend;
 
/**
/**
* Callback Controller constructor.
* Callback Controller constructor.
*
*
@@ -56,16 +72,20 @@ class EloquaApiClient {
@@ -56,16 +72,20 @@ class EloquaApiClient {
* Cache Backend.
* Cache Backend.
* @param \Drupal\Core\Http\ClientFactory $httpClientFactory
* @param \Drupal\Core\Http\ClientFactory $httpClientFactory
* A Guzzle client object.
* A Guzzle client object.
 
* @param \Drupal\Component\Datetime\TimeInterface $time
 
* The time service.
*/
*/
public function __construct(ConfigFactory $config,
public function __construct(ConfigFactory $config,
LoggerChannelFactoryInterface $loggerFactory,
LoggerChannelFactoryInterface $loggerFactory,
CacheBackendInterface $cacheBackend,
CacheBackendInterface $cacheBackend,
ClientFactory $httpClientFactory) {
ClientFactory $httpClientFactory,
 
TimeInterface $time) {
$this->config = $config->get('eloqua_api_redux.settings');
$this->config = $config->get('eloqua_api_redux.settings');
$this->configTokens = $config->getEditable('eloqua_api_redux.tokens');
$this->configTokens = $config->getEditable('eloqua_api_redux.tokens');
$this->loggerFactory = $loggerFactory;
$this->loggerFactory = $loggerFactory;
$this->cacheBackend = $cacheBackend;
$this->cacheBackend = $cacheBackend;
$this->httpClientFactory = $httpClientFactory;
$this->httpClientFactory = $httpClientFactory;
 
$this->time = $time;
}
}
/**
/**
@@ -327,7 +347,7 @@ class EloquaApiClient {
@@ -327,7 +347,7 @@ class EloquaApiClient {
// Save the token.
// Save the token.
$cacheItem = [
$cacheItem = [
'value' => $value,
'value' => $value,
'expire' => \Drupal::time()->getRequestTime() + $this->eloquaApiCacheAge($key),
'expire' => $this->time->getRequestTime() + $this->eloquaApiCacheAge($key),
];
];
$this->configTokens
$this->configTokens
@@ -349,7 +369,7 @@ class EloquaApiClient {
@@ -349,7 +369,7 @@ class EloquaApiClient {
if ($cache = $this->configTokens->get($type)) {
if ($cache = $this->configTokens->get($type)) {
$response = unserialize($cache, ['allowed_classes' => FALSE]);
$response = unserialize($cache, ['allowed_classes' => FALSE]);
$now = \Drupal::time()->getRequestTime();
$now = $this->time->getRequestTime();
$expire = $response['expire'];
$expire = $response['expire'];
// Manually validate if the token is still fresh.
// Manually validate if the token is still fresh.
Loading