-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Session service factories #4268
Session service factories #4268
Conversation
- Uses "session_config" key, assigned to an array of options, to create a Zend\Session\Config\ConfigInterface instance. - By default, uses SessionConfig as ConfigInterface implementation. - A "config_class" subkey can be used to specify a specific ConfigInterface implementation to use.
- Consumes ConfigInterface, StorageInterface, and SaveHandlerInterface services in order to create a SessionManager instance. Services do not need to be present, as null values will be used by default if not found.
- Marshals arguments from Config service - Proxies to Zend\Session\Storage\Factory for actual creation
- Save handler factory will not be provided by the framework at this time.
- Provide an array of container names in "session_containers" configuration. - Uses `Zend\Session\ManagerInterface` service, if available, when instantiating containers. - Session container services must be prefixed with "SessionContainer\\"
- s/SessionConfig/SessionContainer/
Ping @mwillbanks -- this is what we discussed on IRC yesterday. |
- per php-cs-fixer
* @category Zend | ||
* @package Zend_Session | ||
* @subpackage UnitTests | ||
* @group Zend_Session |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only @group
@weierophinney Here is the feedback that I have on this now that I've had some time to look into it all.
|
- Passes created `SessionManager` instance to `Container::setDefaultManager()`
- New Config service key, "session_manager" - single key for now: "enable_default_container_manager". Defaults to true, meaning "inject the Container". Set to false to disable this behavior.
@mwillbanks I've incorporated your feedback. At this ime:
As for the Container factories, the primary use case goes away when the default settings are used. However, if you disable the default manager functionality, this abstract factory would simplify usage of containers associated with the SessionManager service, as you would no longer need to retrieve the SessionManager prior to creating your Container instances. The secondary use case is still present, however: IoC. Basically, you can then treat the Container instances as services, which ensures that injection of the SessionManager is appropriately done, and breaks you of the habit of instantiating the Containers directly. I'm unsure if we should modify existing code to use these services. A quick check shows that the following components use Containers:
The latter three could easily be updated to pull named containers, as they are managed by a plugin manager already. The Cache session storage adapter could be as well, as we have a proposed abstract factory for storage adapters. The CSRF validator falls under this as well, since we have a Validator plugin manager and factory. That leaves Authentication, CAPTCHA, and ProgressBar as outliers, however. Question: should I update those components that we can with this PR, or wait until this one is merged? Ideally, I'd like to get this into 2.2.0, as this, and the Log and Cache factories, have been much requested since 2.0. |
@weierophinney i think we can update those components at a later time and get this in first. Looks like travis had some issues with it on 5.4. |
@mwillbanks The failures on 5.4 are due to issues with Travis-CI properly resolving the path to the downloaded |
Im using thies factories to intitiate my Session Manager, the problem is that when i initialize the Session Manager onBoostrap, the Session Upload Progress var is removed from the $_SESSION var. Im using the SessionArrayStorage the upload progress key is always removed. I also tried disabling the initialization but then my session object gets invalid as the upload progress key is not processed by the SessionArrayStorage so my session is lost after the upload. Is the Session Manager compatible with session upload progress?. |
@rumeau Can you please open a new issue instead of a comment thread inside a closed PR? :) This will allow us to track it separately. Thanks in advance! |
- per php-cs-fixer
This pull request provides
ServiceManager
factories for theZend\Session
component. It includes the following:Zend\Session\Storage\Factory
class for creating instances of storage adapters. This is completely de-coupled from theServiceManager
.Zend\Session\Service
namespace with the following:SessionConfigFactory
, for instantiating a session configuration object. This utilizes thesession_config
key of theConfig
service. If aconfig_class
subkey is available, the class name it defines will be used as the configuration class. The entiresession_config
array is passed to the configuration class'ssetOptions()
method. This factory should be assigned to the service nameZend\Session\Config\ConfigInterface
.StorageFactory
, for instantiating a storage instance. It utilizes thesession_storage
key of theConfig
service, and expects it to be in the format:The type and options are passed to
Zend\Session\Storage\Factory
to create and return an instance. This factory should be assigned to the service nameZend\Session\Storage\StorageInterface
.SessionManagerFactory
, for instantiating aZend\Session\SessionManager
instance. If any of the servicesZend\Session\Config\ConfigInterface
,Zend\Session\Storage\StorageInterface
, orZend\Session\SaveHandler\SaveHandlerInterface
are present, they will be used to instantiate theSessionManager
instance. This service should be assigned to the service nameZend\Session\ManagerInterface
.ContainerAbstractFactory
, for instantiatingZend\Session\Container
instances. It uses thesession_containers
key of theConfig
service, and expects the value of that key to be an array of container names. If aZend\Session\ManagerInterface
service is present, it will be used to instantiateContainer
instances. Container service names MUST be prefixed withSessionContainer\
for the factory to match. This means that the following definition:defines the services
SessionContainer\foo
andSessionContainer\Captcha
.All factories are completely opt-in, and
Zend\ServiceManager
has been added as an optional dependency.As a full example of configuration:
You would then retrieve services within factories as follows: