Skip to content

Commit

Permalink
Update BunqContext with new ApiContext on reset. (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Apr 7, 2018
1 parent abc6437 commit ea35012
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,18 @@ private function dropSessionContext()
/**
* Check if current time is too close to the saved session expiry time and reset session if
* needed.
*
* @return bool
*/
public function ensureSessionActive()
public function ensureSessionActive(): bool
{
if (!$this->isSessionActive()) {
$this->resetSession();

return true;
}

return false;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Http/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace bunq\Http;

use bunq\Context\ApiContext;
use bunq\Context\BunqContext;
use bunq\Exception\BunqException;
use bunq\Http\Handler\HandlerUtil;
use bunq\Http\Handler\RequestHandlerAuthentication;
Expand Down Expand Up @@ -223,7 +224,9 @@ private function request(
private function initialize(string $uri)
{
if (!isset(self::URIS_NOT_REQUIRING_ACTIVE_SESSION[$uri])) {
$this->apiContext->ensureSessionActive();
if ($this->apiContext->ensureSessionActive()) {
BunqContext::updateApiContext($this->apiContext);
}
}

$this->initializeHttpClient();
Expand Down

0 comments on commit ea35012

Please sign in to comment.