Session Handler and Registry

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Since I would like for the database interaction to be as lightweight as possible here (and as portable as possible), I am thinking about just supplying the session handler with a database connection resource in its constructor and then build individual handlers for each type of database I need to use, and effectively elimitate ADOdb from this class completely.I do not like having that dependancy anyway.

This would allow me to take advantage of database-type-specific functionality such as mysql's "replace" as well. What do you guys think?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd use Composition. Make the session handler storage medium agnostic by giving it a known interface that isn't, in itself, specific to any medium of storage. The implementation inside this interface could store the actual data in any location from there, be it database, files, or a mixture of the two.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

feyd wrote:I'd use Composition. Make the session handler storage medium agnostic by giving it a known interface that isn't, in itself, specific to any medium of storage. The implementation inside this interface could store the actual data in any location from there, be it database, files, or a mixture of the two.
Maybe I misunderstand you, but isn't that what I am doing with the SessionSaveHandler interface?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The Ninja Space Goat wrote:Maybe I misunderstand you, but isn't that what I am doing with the SessionSaveHandler interface?
Apparently, yes. :D I was responding to your most recent post about storing a database connection resource in its constructor. That read to me that you'd be given the session class itself the resource. I clearly hadn't read your entire code when I posted.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

so, I did something right!! Woohoo! lol
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Was I correct in understanding that your idea is to give the session class itself the resource or was it the SessionSaveHandler derivative? Going with the former starts down the slope while the latter keeps it associated with the thing that will care about such nonsense. That was the major point I was trying to get across.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I have made the changes and updated that classes. Please let me know what y'all think.
Jenk wrote:FYI: you can scratch your @todo for function clean() because $max is the time in miliseconds that a session expires, the PHP engine provides this time.
Thanks :wink:
Jenk wrote:And furthermore.. when specifying optional arguments like you have done, you should always declare mandatory arguments first:

Code: Select all

public function __construct(ADOConnection $db, $namespace='Session', $regenerate=null){
otherwise your optional args are no longer optional :)
My problem with that is that it changes the way you access the session class... which I don't like. I want it to be the same, regardless of how it stores the data. I will have to think about this one.... I set up a fix I think will work for now

EDIT: I suppose it really is impossible to do that now that I think about it... it's going to be different no matter what because I HAVE to supply the link. hmm...
Post Reply