-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/is expired#58 #59
Changes from 3 commits
718f79b
24387ab
18d62ca
e2da44c
4b30d69
80a3a70
91f95fb
552ef46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,15 +273,19 @@ private function dropSessionContext() | |
*/ | ||
public function ensureSessionActive() | ||
{ | ||
if (is_null($this->sessionContext)) { | ||
return; | ||
if (!is_null($this->sessionContext) && $this->isSessionExpired()) { | ||
$this->resetSession(); | ||
} | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isSessionExpired(): bool | ||
{ | ||
$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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you do Also, I'd go for an explanatory variable here. I missed it when initially built So something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bueno |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for
is_null($this->sessionContext)
can go from here, because you do it inisSessionExpired
already :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you follow my suggestion and change
isSessionExpired
toisSessionActive
orhasActiveSession
, Please do not forget to add an exclamation mark here (only reset if NOT has an active session :))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm AFAIK if we do this then if session is null it will run in an infinite loop resetting the session. At least that was my expiernce in Java 🤔 will double check to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea! The infinite loop:
And it also fails because:
This will cause an error as of
sessionContext
is null! So therefore we need!is_null($this->sessionContext)
inensureSessionActive
still 🤔. The nullsessionContext
will get handled higher up the code before a request is made.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but then based on your suggestion below this can be fixed 👍