/** * This method will attempt to retrieve authentication data from the cache. If none is found it * will defer to the API client being decorated to perform a new authentication attempt against * the API directly. This response will then be cached. * * The authentication is cached to reduce the number of authentication requests which need to be * made to the API. * * @param string $key The API key to authenticate with. * @param array $headers The HTTP headers to be sent with the request. * @param array $options Extra options that may be passed into the request. This argument * mostly exists to facilitate the decorators. Possible keys used by * this decorator include 'force'. * * @return array The API response structure. * */ public function authenticate($key, array $headers = array(), array $options = array()) { /* If the force key is present we should force the decorator to retrieve new data from the * API even if cached data was found. */ $options['force'] = array_key_exists('force', $options) ? $options['force'] : false; // Generate a cache key $cacheKey = $this->cacheKeyFromApiKey($key); // var_dump($cacheKey); exit; // Attempt to retrieve the token from the cache. $result = $this->service->cacheGet($cacheKey); // var_dump($result); exit; // If we don't have a token at this point we need to get one from the API. if ($options['force'] || $result === null) { // Retrieve a token from the API if one was not in the cache. $result = $this->client->authenticate($key, $headers, $options); // Put the new token into the cache. $this->service->cachePut($cacheKey, $result, self::AUTH_CACHE_SPAN); } else { $result['fromCache'] = true; } $result['cacheKey'] = $cacheKey; return $result; }
/** * This method just passes the authentication request off to the decorated client. * * @param string $key The API key to be used to authenticate with the API. * @param array $headers The HTTP headers to be sent with the request. * @param array $options Extra options that may be passed into the request. This parameter * mostly exists to facilitate the decorators. * * @return array The API response structure * */ public function authenticate($key, array $headers = array(), array $options = array()) { return $this->client->authenticate($key, $headers, $options); }
/** * This method just passes the authentication request off to the decorated client. * * @param string $key The API key to be used to authenticate with the API. * @param array $headers The HTTP headers to be sent with the request. * @param array $options Extra options that may be passed into the request. This parameter * mostly exists to facilitate the decorators. * * @return array The API response structure * */ public function authenticate($key, array $headers = array(), array $options = array()) { $this->injectStatHeaders($headers); return $this->client->authenticate($key, $headers, $options); }