[Solar-talk] Adapter-aware session package
Antti Holvikari
anttih at gmail.com
Wed Oct 31 15:37:20 CDT 2007
Hi All!
I created an adapter-aware session package which is now available at
the lux svn repo[1].
I also added two adapters:
* `Phpsession` for normal PHP sessions with *no* userland save handler
* `Cache` - adapter that uses Solar_Cache internally
Default adapter is Phpsession, which basicly does nothing. You can
change adapter with the config key `adapter` like this:
$config['Solar_Session']['adapter'] = 'Solar_Session_Adapter_Cache';
`Solar_Session_Adapter_Cache` accepts Solar_Cache dependency as the
`cache` config key.
As Paul pointed out at #solarphp, he's not sure if the session class
should use Solar_Cache at all. I'm not sure either, *but* if you think
about it, they map very well together. The cache key is the PHPSESSID
and the cache lifetime is same as cookie lifetime. This needs some
more thinking, though. I created it in order to test/demonstrate a
custom save handler.
Solar_Session_Adapter sets cookie params with
session_set_cookie_params(). Every param that it accepts is a config
key. For example, you can set cookie lifetime to something big which
would allow you to have persistent sessions, a.k.a a "Remember me"
-feature.
One problem we need to solve is that it doesn't make sense to
instantiate a Solar_Session instance for every `$_SESSION['class']`
-storage-space. So, I created a Solar_Session_Store class which
handles reading and writing to $_SESSION array. This class is intended
to be instantiated for every class that needs storage-space in
$_SESSION. This means you'd instantiate Solar_Session_Store instead of
Solar_Session directly.
Flash values are stored in $_SESSION['class']['flash']. They could be
directly under $_SESSION['flash'] too, like they are now.
Things that need some consideration:
* Solar_cache may not be the right thing for a session package. Should
we (re)write adapters for, say, memcached?
* Do we need to wrap session_* functions into Solar_Session? The only
one Solar needs now is session_write_close().
I'd really like to hear your opinions. Do you find something like this
useful? Please comment in any way you like :-).
[1] http://lux.googlecode.com/svn/trunk/Solar/Session
--
Antti Holvikari
More information about the Solar-talk
mailing list