Skip to content

Commit

Permalink
Merge pull request #153 from zumba/static-binding
Browse files Browse the repository at this point in the history
Updated API to use late static binding
  • Loading branch information
Raph22 authored Nov 25, 2019
2 parents 85304ce + 66a6fdd commit 5e1089e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/Prismic/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function __construct(
$this->data = $data;
$this->accessToken = $accessToken;
$this->httpClient = is_null($httpClient) ? new Client() : $httpClient;
$this->cache = is_null($cache) ? self::defaultCache() : $cache;
$this->cache = is_null($cache) ? static::defaultCache() : $cache;
}

/**
Expand All @@ -83,7 +83,7 @@ private function __construct(
* @param ClientInterface $httpClient Custom Guzzle http client
* @param CacheInterface $cache Cache implementation
* @param int $apiCacheTTL Max time to keep the API object in cache (in seconds)
* @return self
* @return static
*/
public static function get(
string $action,
Expand All @@ -92,12 +92,12 @@ public static function get(
?CacheInterface $cache = null,
int $apiCacheTTL = 5
) : self {
$cache = is_null($cache) ? self::defaultCache() : $cache;
$cache = is_null($cache) ? static::defaultCache() : $cache;
$cacheKey = $action . (empty($accessToken) ? "" : ("#" . $accessToken));
$apiData = $cache->get($cacheKey);

if (is_string($apiData) && ! empty($apiData)) {
return new self(unserialize($apiData), $accessToken, $httpClient, $cache);
return new static(unserialize($apiData), $accessToken, $httpClient, $cache);
}

$url = $accessToken ? Utils::buildUrl($action, [ 'access_token' => $accessToken]) : $action;
Expand All @@ -110,7 +110,7 @@ public static function get(
}

$apiData = ApiData::withJsonString((string) $response->getBody());
$api = new self($apiData, $accessToken, $httpClient, $cache);
$api = new static($apiData, $accessToken, $httpClient, $cache);
$cache->set($cacheKey, serialize($apiData), $apiCacheTTL);

return $api;
Expand Down
4 changes: 2 additions & 2 deletions src/Prismic/ApiData.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function __construct(
/**
* Return a new ApiData instance from the given JSON string
* @param string $json
* @return self
* @return static
*/
public static function withJsonString(string $json) : self
{
Expand All @@ -111,7 +111,7 @@ public static function withJsonString(string $json) : self
json_last_error_msg()
), json_last_error());
}
return self::withJsonObject($data);
return static::withJsonObject($data);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Prismic/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public function defaultData() : array
/**
* Return a new instance from a JSON string
* @param string $json
* @return self
* @return static
*/
public static function withJsonString(string $json) : self
{
$data = \json_decode($json);
return self::withJsonObject($data);
return static::withJsonObject($data);
}

/**
Expand Down

0 comments on commit 5e1089e

Please sign in to comment.