What are valid values for framework.session.storage_id? What are valid values for framework.session.storage_id? symfony symfony

What are valid values for framework.session.storage_id?


Valid values for framework.session.storage_id are following:

  • session.storage.mock_file - for testing. It doesn't start session at all.
  • session.storage.filesystem - for testing. It is an alias for session.storage.mock_file.
  • session.storage.native - default implementation using defined session handler
  • session.storage.php_bridge - for legacy apps

From developer perspective, there is a session service that abstracts working with session. session service depends on some session storage service. Session storage implements session management from PHP perspective (calling session_start() function for example). Storage also depends on some session handler. Handler is implementation of \SessionStorage and it tells how and where will be session physically stored.

This three layer design allows creating storage for testing which does not call session_start() at all and does not use handler (session.storage.mock_file). Or creating of handler that can store and load session from anywhere (session.storage.native). session.storage.php_bridge solves situation when session_start() is called by external PHP code (not by Symfony session storage).

I hope it is clear to understand.


Session management in Symfony is based on two main rules.

  1. Symfony must start the session.
  2. The Symfony sessions are designed to replace the use of PHP native functions session_*() and $_SESSION global.

However, some exceptions exist. Sometimes it may be necessary to integrate Symfony in a legacy application, which starts the session with session_start().With session.storage.php_bridge directive, you can manage the session using a special gateway that is designed to allow to Symfony working with a session that was started outside the framework.

In goal to make the code using sessions testable, session.storage.mock_file directive allows to simulate the flow of a PHP session without starting it really.