What are valid values for framework.session.storag

2020-07-18 03:55发布

In the Symfony configuration there is an entry framework.session.storage_id. This setting also appears in the default config on the Symfony configuration documentation but it is not explained. My assumption is that it defines where session data is stored on the server side.

Values I have seen for this entry include session.storage.mock_file, session.storage.native and session.storage.filesystem. I am unsure of what these values exactly mean (e.g. what is the difference between a mock file and a filesystem?) and also think that this is not the complete list of possible values.

So what exactly does this configuration key control and what values are valid?

2条回答
姐就是有狂的资本
2楼-- · 2020-07-18 04:32

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.

查看更多
家丑人穷心不美
3楼-- · 2020-07-18 04:51

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.

查看更多
登录 后发表回答