@@ -88,13 +88,12 @@ public static function useHeaders($headers) {
8888 /**
8989 * Start new or resume existing session.
9090 *
91- * @param array $opions If provided, this is an associative array of options that will override the currently set session configuration directives.
92- * http://php.net/manual/en/session.configuration.php
91+ * @param HttpSessionProvider $sessionProvider The session provider to set.
9392 *
9493 * @return void
9594 */
96- public static function useSession ($ opions = null ) {
97- self ::$ config ['session ' ] = (! empty ( $ opions ) ? $ opions : true );
95+ public static function useSession ($ sessionProvider = null ) {
96+ self ::$ config ['sessionProvider ' ] = (isset ( $ sessionProvider ) ? $ sessionProvider : true );
9897 }
9998
10099 /**
@@ -287,30 +286,31 @@ private static function init() {
287286
288287 $ config ['cacheProvider ' ]->init ();
289288
289+ if (isset ($ config ['sessionProvider ' ])) {
290+ if ($ config ['sessionProvider ' ] === true ) {
291+ $ config ['sessionProvider ' ] = new HttpSession ();
292+ }
293+ elseif (!$ config ['sessionProvider ' ] instanceof HttpSessionProvider) {
294+ throw new \Exception ('The $sessionProvider type must be the base of "\PhpMvc\HttpSessionProvider". ' );
295+ }
296+
297+ $ config ['sessionProvider ' ]->init ();
298+ }
299+
290300 if (empty ($ config ['httpContext ' ])) {
291301 $ info = new HttpContextInfo ();
292302 $ info ->routeProvider = $ config ['routeProvider ' ];
293303 $ info ->cacheProvider = $ config ['cacheProvider ' ];
294304 $ info ->request = new HttpRequest ();
295305 $ info ->response = new HttpResponse ();
296- $ info ->session = $ _SESSION ;
306+ $ info ->session = $ config [ ' sessionProvider ' ] ;
297307
298308 $ config ['httpContext ' ] = new HttpContext ($ info );
299309 }
300310 elseif (!$ config ['httpContext ' ] instanceof HttpContextBase) {
301311 throw new \Exception ('The httpContext type must be the base of "\PhpMvc\HttpContextBase". ' );
302312 }
303313
304- if (isset ($ config ['session ' ])) {
305- // TODO: session provider
306- if (is_array ($ config ['session ' ])) {
307- session_start ($ config ['session ' ]);
308- }
309- else {
310- session_start ();
311- }
312- }
313-
314314 // default response handlers
315315 $ response = $ config ['httpContext ' ]->getResponse ();
316316
0 commit comments