Skip to content

Commit

Permalink
Added isExpired() method #58.
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Oct 12, 2017
1 parent 92a6d8f commit 718f79b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,21 @@ private function dropSessionContext()
*/
public function ensureSessionActive()
{
if (is_null($this->sessionContext)) {
return;
if (!is_null($this->sessionContext) && $this->isExpired()) {
$this->resetSession();
}
}

/**
* Checks if the session has expired
*
* @return bool
*/
public function isExpired()
{
$timeExpiry = $this->sessionContext->getExpiryTime()->getTimestamp();

if ($timeExpiry - time() < self::TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS) {
$this->resetSession();
}
return is_null($this->sessionContext) || $timeExpiry - time() < self::TIME_TO_SESSION_EXPIRY_MINIMUM_SECONDS;
}

/**
Expand Down

0 comments on commit 718f79b

Please sign in to comment.