@@ -175,34 +175,23 @@ protected function registerSessionHandler()
175175 static ::$ _originalSessionModule = $ sessionModuleName ;
176176 }
177177
178+ if ($ this ->handler === null && $ this ->getUseCustomStorage ()) {
179+ $ this ->handler = Yii::createObject (
180+ [
181+ '__class ' => SessionHandler::class,
182+ '__construct() ' => [$ this ],
183+ ]
184+ );
185+ }
186+
178187 if ($ this ->handler !== null ) {
179- if (! is_object ($ this ->handler )) {
188+ if (is_array ($ this ->handler )) {
180189 $ this ->handler = Yii::createObject ($ this ->handler );
181190 }
182191 if (!$ this ->handler instanceof \SessionHandlerInterface) {
183192 throw new InvalidConfigException ('" ' . get_class ($ this ) . '::handler" must implement the SessionHandlerInterface. ' );
184193 }
185194 YII_DEBUG ? session_set_save_handler ($ this ->handler , false ) : @session_set_save_handler ($ this ->handler , false );
186- } elseif ($ this ->getUseCustomStorage ()) {
187- if (YII_DEBUG ) {
188- session_set_save_handler (
189- [$ this , 'openSession ' ],
190- [$ this , 'closeSession ' ],
191- [$ this , 'readSession ' ],
192- [$ this , 'writeSession ' ],
193- [$ this , 'destroySession ' ],
194- [$ this , 'gcSession ' ]
195- );
196- } else {
197- @session_set_save_handler (
198- [$ this , 'openSession ' ],
199- [$ this , 'closeSession ' ],
200- [$ this , 'readSession ' ],
201- [$ this , 'writeSession ' ],
202- [$ this , 'destroySession ' ],
203- [$ this , 'gcSession ' ]
204- );
205- }
206195 } elseif (
207196 $ sessionModuleName !== static ::$ _originalSessionModule
208197 && static ::$ _originalSessionModule !== null
@@ -610,7 +599,7 @@ public function closeSession()
610599 * This method should be overridden if [[useCustomStorage]] returns true.
611600 * @internal Do not call this method directly.
612601 * @param string $id session ID
613- * @return string the session data
602+ * @return string|false the session data, or false on failure
614603 */
615604 public function readSession ($ id )
616605 {
@@ -647,11 +636,11 @@ public function destroySession($id)
647636 * This method should be overridden if [[useCustomStorage]] returns true.
648637 * @internal Do not call this method directly.
649638 * @param int $maxLifetime the number of seconds after which data will be seen as 'garbage' and cleaned up.
650- * @return bool whether session is GCed successfully
639+ * @return int|false the number of deleted sessions on success, or false on failure
651640 */
652641 public function gcSession ($ maxLifetime )
653642 {
654- return true ;
643+ return 0 ;
655644 }
656645
657646 /**
0 commit comments