Skip to content

Commit

Permalink
Added method to only update the ApiContext of BunqContext. (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Apr 7, 2018
1 parent f13be0f commit abc6437
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/Context/BunqContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ public static function loadApiContext(ApiContext $apiContext)

/**
* @return ApiContext
* @throws BunqException
*/
public static function getApiContext(): ApiContext
{
if (is_null(static::$apiContext)) {
throw new BunqException(self::ERROR_API_CONTEXT_HAS_NOT_BEEN_LOADED);
} else {
return static::$apiContext;
}
static::assertApiContextHasBeenLoaded();

return static::$apiContext;
}

/**
Expand All @@ -62,4 +59,27 @@ public static function getUserContext(): UserContext
return static::$userContext;
}
}

/**
* @param ApiContext $apiContext
*/
public static function updateApiContext(ApiContext $apiContext)
{
static::assertApiContextHasBeenLoaded();

static::$apiContext = $apiContext;
}

/**
* @return bool
* @throws BunqException
*/
private static function assertApiContextHasBeenLoaded(): bool
{
if (is_null(static::$apiContext)) {
throw new BunqException(self::ERROR_API_CONTEXT_HAS_NOT_BEEN_LOADED);
}

return true;
}
}

0 comments on commit abc6437

Please sign in to comment.