Skip to content

Commit

Permalink
Merge pull request #147 from paynl/feature/PLUG-691
Browse files Browse the repository at this point in the history
PLUG-691 - Version overrule
  • Loading branch information
woutse authored Oct 12, 2021
2 parents 756f43f + f8d1461 commit 88e392d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function doRequest($endpoint, $version = null)
if ($version === null) {
$version = $this->version;
}

$auth = $this->getAuth();
$data = $this->getData();
$uri = Config::getApiUrl($endpoint, (int) $version);
Expand Down
15 changes: 11 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Config
*/
private static $apiVersion = 5;

/**
* @var bool Boolean to force using the API version set by this config.
*/
private static $forceApiVersion = false;

private static $curl;

/**
Expand Down Expand Up @@ -169,14 +174,16 @@ public static function setServiceId($serviceId)
public static function getApiVersion()
{
return self::$apiVersion;
}
}

/**
* @param string $apiVersion The API version to use for requests.
* @param bool $forceUse Set to true if you want to force using this version.
*/
public static function setApiVersion($apiVersion)
public static function setApiVersion($apiVersion, $forceUse = false)
{
self::$apiVersion = (int) $apiVersion;
self::$forceApiVersion = $forceUse;
}

/**
Expand All @@ -187,9 +194,9 @@ public static function setApiVersion($apiVersion)
*/
public static function getApiUrl($endpoint, $version = null)
{
if ($version === null) {
if ($version === null || self::$forceApiVersion) {
$version = self::$apiVersion;
}
}
return self::$apiBase . '/v' . $version . '/' . $endpoint . '/json';
}

Expand Down

0 comments on commit 88e392d

Please sign in to comment.