[PATCH] session_set_save_handler(class)
| From: | Arpad Ray | Date: | Sun, 22 Nov 2009 05:12:19 +0000 |
| Subject: | [PATCH] session_set_save_handler(class) | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-46156@lists.php.net to get a copy of this message | ||
Attached is a patch (against HEAD, includes tests) which allows users to
extend any session handler in an object oriented fashion.
By extending the new internal class SessionHandler, users can wrap or
override methods of whatever session handler is in use, or implement a
complete custom handler.
Usage notes:
- Calling session_set_save_handler(class) after session_set_save_handler(a,
b, c, d, e, f) wouldn't transparently extend the first call since they share
the same storage. However this can be achieved by calling the former
functions manually from the class.
- Likewise multiple session_set_save_handler(class) calls simply replace
each other; just extend the new class from the old one instead of
SessionHandler to chain them.
Implementation notes:
- mod_user.c was faking PS(mod_data) so it would get called at the right
times. Now that we need to preserve the data for whatever handler we're
wrapping, session.c checks the new global PS(mod_active) instead. No more
tests are failing but I think it's possible this could break existing user
session modules so please look at this carefully. We could just do
PS(mod_data) || PS(var_controlled_by_mod_user) to be on the safe side, at
the expense of a very slight overhead for other session modules.
I've experimented with a few different ways of approaching this already.
Although I like this one (reusing the mod_user callbacks) because the change
is pretty minimal, it might be better to just store a pointer to the class
entry or the function entries. Or something entirely different..
I'd be grateful for any comments.
Arpad
Attachment: [text/x-diff] php6-session-oo.patch
Attachment: [text/x-diff] php6-session-oo.patch