Skip to content

Commit

Permalink
Merge pull request #115 from bunq/hotifx/bunq_context_class_name
Browse files Browse the repository at this point in the history
Renamed filename accordingly. #114
  • Loading branch information
OGKevin authored Mar 21, 2018
2 parents 4b9708c + 7a4dc4c commit 6a58367
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/Context/BunqContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace bunq\Context;

use bunq\Exception\BunqException;

class BunqContext
{
/**
* Error constants.
*/
const ERROR_API_CONTEXT_HAS_NOT_BEEN_LOADED = 'apiContext has not been loaded.';
const ERROR_USER_CONTEXT_NOT_LOADED = 'userContext has not been loaded, you can load this by loading apiContext.';

/**
* @var ApiContext
*/
protected static $apiContext;

/**
* @var UserContext
*/
protected static $userContext;

/**
*/
private function __construct()
{
}

/**
* @param ApiContext $apiContext
*/
public static function loadApiContext(ApiContext $apiContext)
{
static::$apiContext = $apiContext;
static::$userContext = new UserContext($apiContext->getSessionContext()->getUserId());
static::$userContext->initMainMonetaryAccount();
}

/**
* @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;
}
}

/**
* @return UserContext
* @throws BunqException
*/
public static function getUserContext(): UserContext
{
if (is_null(static::$userContext)) {
throw new BunqException(self::ERROR_USER_CONTEXT_NOT_LOADED);
} else {
return static::$userContext;
}
}
}

0 comments on commit 6a58367

Please sign in to comment.