-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow setting session lifetime from middleware before starting session #17964
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
Allow setting session lifetime from middleware before starting session #17964
Conversation
| * @return void | ||
| * @throws \Cake\Core\Exception\CakeException | ||
| */ | ||
| public function setSessionLifetime(int $lifetime): void |
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.
Instead of special casing session lifetime how about we add a general setConfig() to allow changing any session config before the session is started?
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.
The issue would be that this config variable is only read in constructor, and also have some side-effects when setting it.
So using setConfig would not set the session.gc_maxlifetime, and adding it would also require to change the _timedOut() to read directly from config.
But yes, if the logic that is in constructor would be moved and executed when starting session ... that would make sense.
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.
Yes, all the code in the constructor (barring last 2 lines probably) would be moved into the new setConfig() method and then the constructor can call that method.
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.
Thinking about this again, having a separate method to update only the session lifetime is good enough since we already have separate public methods for ini config options() and the handler engine().
|
Ping @kolorafa |
Co-authored-by: ADmad <[email protected]>
Co-authored-by: ADmad <[email protected]>
Co-authored-by: ADmad <[email protected]>
|
Sorry for the delay, the tasks at work got shifted and the scheduled time to work on those PR got delayed :( |
Ability to change session lifetime in Middleware (so after already having created Session instance) but before session started (as this is used when starting a session).
The purpose is to have the session lifetime setting set in database, but fetching data from database in bootstrap have side-effects (like not showing the query in DebugKit, or having wrong db connection if it's configured by another bootstrap file (like a plugin). It is up to developer to correctly order the middlewares.
While currently the only way to change that would be to create new Session instance in middleware and replace it.
Other simpler implementation could be just putting a setter for that private value:
I can make different PR with only the setter if that would be preferred.