33namespace SilverStripe \Control ;
44
55use BadMethodCallException ;
6+ use SilverStripe \Control \SessionHandler \FileSessionHandler ;
67use SilverStripe \Core \Config \Configurable ;
8+ use SilverStripe \Core \Injector \Injector ;
79
810/**
911 * Handles all manipulation of the session.
@@ -119,6 +121,7 @@ class Session
119121 /**
120122 * @config
121123 * @var string
124+ * @deprecated 6.1.0 Use `session.save_path` in ini configuration instead.
122125 */
123126 private static $ session_store_path ;
124127
@@ -139,6 +142,7 @@ class Session
139142 *
140143 * @see https://secure.php.net/manual/en/function.session-cache-limiter.php
141144 * @var string|null
145+ * @deprecated 6.1.0 Will be removed without equivalent functionality to replace it
142146 */
143147 private static $ sessionCacheLimiter = '' ;
144148
@@ -150,6 +154,12 @@ class Session
150154 */
151155 private static $ strict_user_agent_check = true ;
152156
157+ /**
158+ * FQCN or injector service name for the session save handler.
159+ * If null, the save handler defined in `session.save_handler` ini configuration is used.
160+ */
161+ private static ?string $ save_handler = FileSessionHandler::class;
162+
153163 /**
154164 * Session data.
155165 * Will be null if session has not been started
@@ -299,6 +309,13 @@ public function start(HTTPRequest $request)
299309 session_save_path ($ session_path );
300310 }
301311
312+ // Set the session save handler if configured
313+ $ saveHandlerServiceName = static ::config ()->get ('save_handler ' );
314+ if ($ saveHandlerServiceName !== null ) {
315+ $ saveHandler = Injector::inst ()->get ($ saveHandlerServiceName );
316+ session_set_save_handler ($ saveHandler , true );
317+ }
318+
302319 session_start ();
303320
304321 // Session start emits a cookie, but only if there's no existing session. If there is a session timeout
0 commit comments