From: Brad Jorsch Date: Wed, 10 Feb 2016 16:49:19 +0000 (-0500) Subject: PHPSessionHandler: Implement SessionHandlerInterface X-Git-Tag: 1.31.0-rc.0~8007^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=0f6b181c7355aba61a7d429f91e3662bb7473c86;p=lhc%2Fweb%2Fwiklou.git PHPSessionHandler: Implement SessionHandlerInterface Now that support for PHP 5.3 has been dropped, we can do this. Change-Id: If7fa9801194683eea6764e5748157d8a66a616df --- diff --git a/includes/session/PHPSessionHandler.php b/includes/session/PHPSessionHandler.php index 795e253254..7d7e1cb77e 100644 --- a/includes/session/PHPSessionHandler.php +++ b/includes/session/PHPSessionHandler.php @@ -28,13 +28,10 @@ use BagOStuff; /** * Adapter for PHP's session handling - * @todo Once we drop support for PHP < 5.4, use SessionHandlerInterface - * (should just be a matter of adding "implements SessionHandlerInterface" and - * changing the session_set_save_handler() call). * @ingroup Session * @since 1.27 */ -class PHPSessionHandler { +class PHPSessionHandler implements \SessionHandlerInterface { /** @var PHPSessionHandler */ protected static $instance = null; @@ -132,20 +129,9 @@ class PHPSessionHandler { // Also set a sane serialization handler \Wikimedia\PhpSessionSerializer::setSerializeHandler(); - session_set_save_handler( - array( self::$instance, 'open' ), - array( self::$instance, 'close' ), - array( self::$instance, 'read' ), - array( self::$instance, 'write' ), - array( self::$instance, 'destroy' ), - array( self::$instance, 'gc' ) - ); - - // It's necessary to register a shutdown function to call session_write_close(), - // because by the time the request shutdown function for the session module is - // called, other needed objects may have already been destroyed. Shutdown functions - // registered this way are called before object destruction. - register_shutdown_function( array( self::$instance, 'handleShutdown' ) ); + // Register this as the save handler, and register an appropriate + // shutdown function. + session_set_save_handler( self::$instance, true ); } /** @@ -368,18 +354,4 @@ class PHPSessionHandler { $this->store->deleteObjectsExpiringBefore( $before ); return true; } - - /** - * Shutdown function. - * - * See the comment inside self::install for rationale. - * @codeCoverageIgnore - * @private For internal use only - */ - public function handleShutdown() { - if ( $this->enable ) { - session_write_close(); - } - } - }