From cd0b3696c4ce94588a4995f72c9f1447da50d406 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Thu, 21 Nov 2024 14:33:46 -0700 Subject: [PATCH 1/5] Make nullable type in modAccessibleObject::checkPolicy() explicit --- core/src/Revolution/Sources/modMediaSource.php | 6 +++--- core/src/Revolution/modAccessibleObject.php | 4 ++-- core/src/Revolution/modNamespace.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/Revolution/Sources/modMediaSource.php b/core/src/Revolution/Sources/modMediaSource.php index 7b359fa1606..5a79d1f94b9 100644 --- a/core/src/Revolution/Sources/modMediaSource.php +++ b/core/src/Revolution/Sources/modMediaSource.php @@ -1173,7 +1173,7 @@ public function uploadObjectsToContainer($container, array $objects = []) $this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage()); } } - + $objects[$key] = $file; } @@ -1672,11 +1672,11 @@ public function findPolicy($context = '') * * @param string|array $criteria * @param array $targets - * @param modUser $user + * @param modUser|null $user * * @return bool */ - public function checkPolicy($criteria, $targets = null, modUser $user = null) + public function checkPolicy($criteria, $targets = null, ?modUser $user = null) { if ($criteria == 'load') { $success = true; diff --git a/core/src/Revolution/modAccessibleObject.php b/core/src/Revolution/modAccessibleObject.php index 95c5eddaecf..171b4b1a787 100644 --- a/core/src/Revolution/modAccessibleObject.php +++ b/core/src/Revolution/modAccessibleObject.php @@ -242,12 +242,12 @@ public function remove(array $ancestors = []) * class names to limit the check. In most cases, this does not need to be * set; derivatives should typically determine what targets to include in * the findPolicy() implementation. - * @param modUser $user + * @param modUser|null $user * * @return boolean Returns true if the policy is satisfied or no policy * exists. */ - public function checkPolicy($criteria, $targets = null, modUser $user = null) + public function checkPolicy($criteria, $targets = null, ?modUser $user = null) { if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) { if (!$user) { diff --git a/core/src/Revolution/modNamespace.php b/core/src/Revolution/modNamespace.php index 7c06ba8a161..37209bd136c 100644 --- a/core/src/Revolution/modNamespace.php +++ b/core/src/Revolution/modNamespace.php @@ -108,7 +108,7 @@ public static function translatePath(xPDO &$xpdo, $path) ], $path); } - public function checkPolicy($criteria, $targets = null, modUser $user = null) + public function checkPolicy($criteria, $targets = null, ?modUser $user = null) { return parent::checkPolicy($criteria, $targets, $user); } From dbbdca08c0594c3f6e8620681fd406ac28c0c814 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Fri, 22 Nov 2024 07:38:03 -0700 Subject: [PATCH 2/5] Remove or isolate E_STRICT references deprecated in PHP 8.4 --- _build/lexicon/checklexicon.php | 2 +- _build/transport.core.php | 2 +- core/src/Revolution/Error/modErrorHandler.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/_build/lexicon/checklexicon.php b/_build/lexicon/checklexicon.php index 33f00a57e6e..57869e9e140 100755 --- a/_build/lexicon/checklexicon.php +++ b/_build/lexicon/checklexicon.php @@ -14,7 +14,7 @@ /* get rid of time limit */ set_time_limit(0); -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', true); $buildConfig = dirname(dirname(__FILE__)) . '/build.config.php'; diff --git a/_build/transport.core.php b/_build/transport.core.php index 9fd9ac802d9..ecd8475899d 100644 --- a/_build/transport.core.php +++ b/_build/transport.core.php @@ -12,7 +12,7 @@ /* get rid of time limit */ set_time_limit(0); -error_reporting(E_ALL | E_STRICT); +error_reporting(E_ALL); ini_set('display_errors', true); /* buildImage can be defined for running against a specific build image diff --git a/core/src/Revolution/Error/modErrorHandler.php b/core/src/Revolution/Error/modErrorHandler.php index c388adca02f..5ce80460061 100644 --- a/core/src/Revolution/Error/modErrorHandler.php +++ b/core/src/Revolution/Error/modErrorHandler.php @@ -37,7 +37,7 @@ class modErrorHandler * @param array $stack A stack of errors that can be passed in. Send a non-array value to * prevent any errors from being recorded in the stack. */ - function __construct(modX &$modx, array $stack = []) + public function __construct(modX &$modx, array $stack = []) { $this->modx = &$modx; $this->stack = $stack; @@ -94,13 +94,6 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $ $errmsg = 'User notice: ' . $errstr; $this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline); break; - case E_STRICT: - $handled = true; - $errmsg = 'E_STRICT information: ' . $errstr; - $this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline); - - return $handled; - break; case E_RECOVERABLE_ERROR: $handled = true; $errmsg = 'Recoverable error: ' . $errstr; @@ -117,6 +110,13 @@ public function handleError($errno, $errstr, $errfile = null, $errline = null, $ $this->modx->log(modX::LOG_LEVEL_WARN, $errmsg, '', '', $errfile, $errline); break; default: + if (version_compare(PHP_VERSION, '8.4.0', '<') && $errno == E_STRICT) { + $handled = true; + $errmsg = 'E_STRICT information: ' . $errstr; + $this->modx->log(modX::LOG_LEVEL_INFO, $errmsg, '', '', $errfile, $errline); + break; + } + $handled = false; $errmsg = 'Un-recoverable error ' . $errno . ': ' . $errstr; $this->modx->log(modX::LOG_LEVEL_ERROR, $errmsg, '', '', $errfile, $errline); From 93a2b230b3aaa468283e8df06b3ad193d3e01553 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Fri, 22 Nov 2024 07:39:02 -0700 Subject: [PATCH 3/5] Make nullable types in modDeprecatedMethod::addCaller() explicit --- core/src/Revolution/modDeprecatedMethod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Revolution/modDeprecatedMethod.php b/core/src/Revolution/modDeprecatedMethod.php index 0e3678a4076..1f93339cbbb 100644 --- a/core/src/Revolution/modDeprecatedMethod.php +++ b/core/src/Revolution/modDeprecatedMethod.php @@ -17,7 +17,7 @@ class modDeprecatedMethod extends \xPDO\Om\xPDOSimpleObject { private $callers = []; - public function addCaller(string $class, string $function, string $file = null, int $line = null) + public function addCaller(string $class, string $function, ?string $file = null, ?int $line = null) { $def = "{$class}::{$function}::{$file}::{$line}"; From 731cf4773857e399c0730fc1e167927fb27a7242 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Fri, 22 Nov 2024 08:41:10 -0700 Subject: [PATCH 4/5] Implement SessionHandlerInterface to avoid deprecation warnings in PHP 8.4 --- core/src/Revolution/modSessionHandler.php | 14 +++++++++++--- core/src/Revolution/modX.php | 21 +++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/core/src/Revolution/modSessionHandler.php b/core/src/Revolution/modSessionHandler.php index be939d6f6a3..0680f23302d 100644 --- a/core/src/Revolution/modSessionHandler.php +++ b/core/src/Revolution/modSessionHandler.php @@ -16,7 +16,7 @@ * * @package MODX\Revolution */ -class modSessionHandler +class modSessionHandler implements \SessionHandlerInterface { /** * @var modX A reference to the modX instance controlling this session @@ -42,7 +42,7 @@ class modSessionHandler * * @param modX &$modx A reference to a {@link modX} instance. */ - function __construct(modX &$modx) + public function __construct(modX &$modx) { $this->modx = &$modx; $gcMaxlifetime = (integer)$this->modx->getOption('session_gc_maxlifetime'); @@ -64,11 +64,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; } @@ -80,6 +83,7 @@ public function open() * @return boolean Always returns true; actual connection is managed by * {@link modX} */ + #[\ReturnTypeWillChange] public function close() { return true; @@ -94,6 +98,7 @@ public function close() * * @return string The data read from the {@link modSession} object. */ + #[\ReturnTypeWillChange] public function read($id) { if ($this->_getSession($id)) { @@ -115,6 +120,7 @@ public function read($id) * * @return boolean True if successfully written. */ + #[\ReturnTypeWillChange] public function write($id, $data) { $written = false; @@ -138,6 +144,7 @@ public function write($id, $data) * * @return boolean True if the session record was destroyed. */ + #[\ReturnTypeWillChange] public function destroy($id) { if ($this->_getSession($id)) { @@ -159,6 +166,7 @@ public function destroy($id) * * @return boolean True if session records were removed. */ + #[\ReturnTypeWillChange] public function gc($max) { $maxtime = time() - $this->gcMaxLifetime; diff --git a/core/src/Revolution/modX.php b/core/src/Revolution/modX.php index 63d87776fa5..39da83491b1 100644 --- a/core/src/Revolution/modX.php +++ b/core/src/Revolution/modX.php @@ -29,6 +29,7 @@ use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; +use SessionHandlerInterface; use xPDO\Cache\xPDOFileCache; use xPDO\xPDO; use xPDO\xPDOException; @@ -2754,14 +2755,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( - [& $sh, 'open'], - [& $sh, 'close'], - [& $sh, 'read'], - [& $sh, 'write'], - [& $sh, 'destroy'], - [& $sh, 'gc'] - ); + if ($sh instanceof SessionHandlerInterface) { + session_set_save_handler($sh); + } else { + session_set_save_handler( + [& $sh, 'open'], + [& $sh, 'close'], + [& $sh, 'read'], + [& $sh, 'write'], + [& $sh, 'destroy'], + [& $sh, 'gc'] + ); + } } } } From 6045bddf136d6d7dd9af0503f53b778f6172c92e Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Fri, 22 Nov 2024 08:47:43 -0700 Subject: [PATCH 5/5] Update CI matrix to include PHP 8.2, 8.3 and 8.4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b99b2a54a6..5975afc111e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: strategy: matrix: - php-version: ['7.2', '7.3', '7.4', '8.0', '8.1'] + php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout