-
Notifications
You must be signed in to change notification settings - Fork 62
Remove default session manager as it introduces hidden dependencies #58
Comments
my two pennies worth on this one: For instance, when the session manager is configured using config options array, if the session manager has not been explicitely instanciated, the Zend\Authentication\AuthenticationService storage container will not use it thus ignoring the configured session. Here 's some pseudo code to make myself clear : let's suppose we have this config :
The following WON'T use the configuration:
BUT this will:
as during instanciation the sessionManager factory will call the static Container::setDefaultManager |
I agree there should be the "default" session manager service in the service manager (and it exists already - it is named |
TL;DR: I agree In the vast majority of cases developers need only reconfigure rather than replace the default session manager. There are a number of provided ways to influence the configuration of the session manager: The default factories for
Documentation for all of these options can be found here: http://zendframework.github.io/zend-session/config/ You could also attach a delegator factory to That said, and as @jcaillot shows, the "magic" injection of the default session scope isn't without it's problems. Personally I do prefer to inject the session manager or session container into the places I need it, and ZF doesn't preclude you from doing that -- the Container "default manager" stuff is a convenience layer but in no way mandatory. In it's current state the only real benefit you get from the Container "default manager" setup is you can do |
@jcaillot this is due to the fact that service manager factories aren't executed until the key is requested. AuthenticationService relies on a session Container instance, and that Container can't fall back to the default SessionManager until the default is injected into it. That default isn't injected until SessionManagerFactory is executed for the first time. In the absence of an injected default session manager, Container will instantiate one without config (here). You've also identified the only feasible workaround at this point: if you have customized session manager configurations you need to pull the session manager somewhere early in the bootstrap process to ensure that your configured session manager becomes the system-wide default. |
This repository has been closed and moved to laminas/laminas-session; a new issue has been opened at laminas/laminas-session#15. |
Currently the
Zend\Session\AbstractContainer
class has thesetDefaultManager()
static method which completely breaks the concept which forces developers to explicitly specify the dependencies for a class, model, controller etc. As a result, many ZF3 components implicitly use the default session manager.If I configure 'not default' session manager, I have to pass it everywhere including controllers, services, validators (like FlashMessenger) etc., but I think this possiblity is not developed enough in ZF3, because all components use default session manager implicitly.
I suggest to remove the static default session manager and force users to configure and provide the session manager explicitly.
The text was updated successfully, but these errors were encountered: