php - who is responsible for cart session management? -


i designed cart site did recently. persistence chose sessions. cart responsible own session management. when cart instantiated, constructor restores cart session, using session facade. when cart destroyed, destructor saves current state of cart session, again using facade. know not good, , in need of refactor.

i see 2 possible routes session management, question is, responsibility manage session? should responsibility of controller save , restore cart , session? or inject session layer cart, , cart still handles internally?

i i've had mixed results using php __destruct(), due fact can called in order during shutdown sequence. think i'd move away using because of unpredictable behavior (unless convinces me otherwise).

one benefit had cart handling own session storage, had handle saving , restoring in 1 place. if go controller route, imagine need restore() , save() every controller method needed in. i'm not opposed if cleans dependencies of cart, prefer write less code.

i know question little open ended , may invite opinion based answers, please provide specific examples of things you've tried have or have not worked, , pros , cons of them.

thanks!

no session handling in controller. that's delegating , consolidating.

sessions should handled session handler. dependency injection can inject handler in constructor. nice maintainability, scalability , testability.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -