We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Best Practice: Integrating Custom Session Handling

I'm evolving a long running application to make use of the Phalcon framework. This app has some very complex session management requirements that I would like to wrap up in a single object and make the methods available through the framework.

I know I'll figure this out, but would appreciate hearing a sentence or two from others on how they would go about this seemingly straightforward task. Thanks.

Easiest way to start would be to wrap your existing management code into a service and have it extend \Phalcon\Mvc\Component, and then register it in your DI

$di->setShared('session', function() use ($di) {
    return new Namespace\To\Custom\Class($di);
});

Alternatively, you could try all of the above but extend \Phalcon\Session, overload phalcons methods, deprecate current code and create your own handler.



1.7k

Ok, the $di route is where my mind was going, but I was not aware of the adapter option.

Will probably have questions on the finer points of the session adapter route. Thanks!