Skip to content

Commit

Permalink
Make session_set_save_handler call compatible with 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
opengeek committed Nov 21, 2024
1 parent d7519ba commit 81226a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
12 changes: 10 additions & 2 deletions core/model/modx/modsessionhandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @package modx
*/
class modSessionHandler {
class modSessionHandler implements SessionHandlerInterface {
/**
* @var modX A reference to the modX instance controlling this session
* handler.
Expand Down Expand Up @@ -60,11 +60,14 @@ function __construct(modX &$modx) {
/**
* Opens the connection for the session handler.
*
* @param $path
* @param $name
* @access public
* @return boolean Always returns true; actual connection is managed by
* {@link modX}.
*/
public function open() {
#[\ReturnTypeWillChange]
public function open($path, $name) {
return true;
}

Expand All @@ -75,6 +78,7 @@ public function open() {
* @return boolean Always returns true; actual connection is managed by
* {@link modX}
*/
#[\ReturnTypeWillChange]
public function close() {
return true;
}
Expand All @@ -86,6 +90,7 @@ public function close() {
* @param integer $id The pk of the {@link modSession} object.
* @return string The data read from the {@link modSession} object.
*/
#[\ReturnTypeWillChange]
public function read($id) {
if ($this->_getSession($id)) {
$data= $this->session->get('data');
Expand All @@ -103,6 +108,7 @@ public function read($id) {
* @param mixed $data The data to write to the session.
* @return boolean True if successfully written.
*/
#[\ReturnTypeWillChange]
public function write($id, $data) {
$written= false;
if ($this->_getSession($id, true)) {
Expand All @@ -122,6 +128,7 @@ public function write($id, $data) {
* @param integer $id
* @return boolean True if the session record was destroyed.
*/
#[\ReturnTypeWillChange]
public function destroy($id) {
if ($this->_getSession($id)) {
$destroyed= $this->session->remove();
Expand All @@ -139,6 +146,7 @@ public function destroy($id) {
* longer than.
* @return boolean True if session records were removed.
*/
#[\ReturnTypeWillChange]
public function gc($max) {
$maxtime= time() - $this->gcMaxLifetime;
return $this->modx->removeCollection('modSession', array("{$this->modx->escape('access')} < {$maxtime}"));
Expand Down
20 changes: 12 additions & 8 deletions core/model/modx/modx.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2564,14 +2564,18 @@ protected function _initSession($options = null) {
if ($sessionHandlerClass = $this->getOption('session_handler_class', $options)) {
if ($shClass = $this->loadClass($sessionHandlerClass, '', false, true)) {
if ($sh = new $shClass($this)) {
session_set_save_handler(
array (& $sh, 'open'),
array (& $sh, 'close'),
array (& $sh, 'read'),
array (& $sh, 'write'),
array (& $sh, 'destroy'),
array (& $sh, 'gc')
);
if ($sh instanceof SessionHandlerInterface) {
session_set_save_handler($sh);
} elseif (version_compare(phpversion(), '8.4.0', '<')) {
session_set_save_handler(
[& $sh, 'open'],
[& $sh, 'close'],
[& $sh, 'read'],
[& $sh, 'write'],
[& $sh, 'destroy'],
[& $sh, 'gc']
);
}
}
}
}
Expand Down

0 comments on commit 81226a7

Please sign in to comment.