[9.x] Add Illuminate\Session\Store::setHandler() #44736
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a simple setter for the handler used by
Illuminate\Session\Store
. The PR doesn't introduce any breaking changes.The use case is that when you're changing database connections on the fly, the database session driver can run into issues where it tries to run queries on a DB connection that no longer exists.
The session-related middleware instantiates
Illuminate\Session\Store
for the database driver which usesDatabaseSessionHandler
as the$handler
. That class stores the connection and is used at the end of the request to write the session data. At that point, the connection that was injected initially may not exist anymore.By adding the setter, I can reconstruct the
DatabaseSessionHandler
on the fly and make it use the correct DB connection: https://gist.github.com/stancl/eb6e210b553bf697c13f19ddaf80f539#file-sessiontenancybootstrapper-php-L18-L38The addition will let me fix archtechx/tenancy#547.