Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.4 compatibility updates #16648

Draft
wants to merge 5 commits into
base: 3.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _build/lexicon/checklexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion _build/transport.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions core/src/Revolution/Error/modErrorHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in core/src/Revolution/Error/modErrorHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace MODX\Revolution\Error;

Check failure on line 11 in core/src/Revolution/Error/modErrorHandler.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line


use MODX\Revolution\modX;
Expand Down Expand Up @@ -37,7 +37,7 @@
* @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;
Expand Down Expand Up @@ -94,13 +94,6 @@
$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;
Expand All @@ -117,6 +110,13 @@
$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);
Expand Down
6 changes: 3 additions & 3 deletions core/src/Revolution/Sources/modMediaSource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
namespace MODX\Revolution\Sources;

use Exception;
Expand Down Expand Up @@ -360,7 +360,7 @@

$directories = $dirNames = $files = $fileNames = [];

if (!empty($path)) {

Check failure on line 363 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Blank line found at start of control structure

// Ensure the provided path can be read.
try {
Expand Down Expand Up @@ -420,7 +420,7 @@
$directories[$file_name]['menu'] = [
'items' => $this->getListDirContextMenu(),
];

Check failure on line 423 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Blank line found at end of control structure
}
elseif ($object instanceof FileAttributes) {
// @TODO review/refactor extension and mime_type would be better for filesystems that
Expand All @@ -434,7 +434,7 @@
continue;
}
$fileNames[] = strtoupper($file_name);
$files[$file_name] = $this->buildFileList($object['path'], $ext, $imageExtensions, $bases, $properties);

Check warning on line 437 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 124 characters
}
}

Expand Down Expand Up @@ -511,13 +511,13 @@
return [];
}
foreach ($contents as $object) {
if (in_array($object['path'], $skipFiles) || in_array(trim($object['path'], DIRECTORY_SEPARATOR), $skipFiles) || (in_array($fullPath . $object['path'], $skipFiles))) {

Check warning on line 514 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 179 characters
continue;
}
if ($object instanceof DirectoryAttributes && !$this->hasPermission('directory_list')) {
continue;
} elseif ($object['type'] == 'file' && !$properties['hideFiles'] && $this->hasPermission('file_list')) {
// @TODO review/refactor ext and mime_type would be better for filesystems that may not always have an extension on it

Check warning on line 520 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 134 characters
// example would be S3 and you have an HTML file but the name is just myPage
//$this->filesystem->getMimetype($object['path']);
$ext = pathinfo($object['path'], PATHINFO_EXTENSION);
Expand All @@ -529,7 +529,7 @@
}
$fileNames[] = strtoupper($object['path']);

$files[$object['path']] = $this->buildFileBrowserViewList($object['path'], $ext, $imageExtensions, $bases, $properties);

Check warning on line 532 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 136 characters
}
}

Expand Down Expand Up @@ -1173,7 +1173,7 @@
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());
}
}

$objects[$key] = $file;
}

Expand Down Expand Up @@ -1636,7 +1636,7 @@
$accessTable = $this->xpdo->getTableName(modAccessMediaSource::class);
$sourceTable = $this->xpdo->getTableName(modMediaSource::class);
$policyTable = $this->xpdo->getTableName(modAccessPolicy::class);
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " .

Check warning on line 1639 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 124 characters
"LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " .
"JOIN {$sourceTable} Source ON Acl.principal_class = {$this->xpdo->quote(modUserGroup::class)} " .
"AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " .
Expand Down Expand Up @@ -1672,11 +1672,11 @@
*
* @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;
Expand Down Expand Up @@ -1725,10 +1725,10 @@
$c->select($this->xpdo->escape('key'));

$options[xPDO::OPT_CACHE_KEY] = $this->getOption('cache_media_sources_key', $options, 'media_sources');
$options[xPDO::OPT_CACHE_HANDLER] = $this->getOption('cache_media_sources_handler', $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options));

Check warning on line 1728 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 155 characters
$options[xPDO::OPT_CACHE_FORMAT] = (integer)$this->getOption('cache_media_sources_format', $options, $this->getOption(xPDO::OPT_CACHE_FORMAT, $options, xPDOCacheManager::CACHE_PHP));

Check warning on line 1729 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 190 characters
$options[xPDO::OPT_CACHE_ATTEMPTS] = (integer)$this->getOption('cache_media_sources_attempts', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 10));

Check warning on line 1730 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 171 characters
$options[xPDO::OPT_CACHE_ATTEMPT_DELAY] = (integer)$this->getOption('cache_media_sources_attempt_delay', $options, $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000));

Check warning on line 1731 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 188 characters

if ($c->prepare() && $c->stmt->execute()) {
while ($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
Expand Down Expand Up @@ -1843,7 +1843,7 @@
$fullPath = $bases['pathAbsolute'] . ltrim($path, DIRECTORY_SEPARATOR);
}

if (!empty($properties['currentFile']) && rawurldecode($properties['currentFile']) == $fullPath . $path && $properties['currentAction'] == $editAction) {

Check warning on line 1846 in core/src/Revolution/Sources/modMediaSource.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 161 characters
$cls[] = 'active-node';
}
if ($this->hasPermission('file_remove') && $canRemove) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/Revolution/modAccessibleObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/Revolution/modDeprecatedMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down
2 changes: 1 addition & 1 deletion core/src/Revolution/modNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 11 additions & 3 deletions core/src/Revolution/modSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @package MODX\Revolution
*/
class modSessionHandler
class modSessionHandler implements \SessionHandlerInterface
{
/**
* @var modX A reference to the modX instance controlling this session
Expand All @@ -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');
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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)) {
Expand All @@ -115,6 +120,7 @@ public function read($id)
*
* @return boolean True if successfully written.
*/
#[\ReturnTypeWillChange]
public function write($id, $data)
{
$written = false;
Expand All @@ -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)) {
Expand All @@ -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;
Expand Down
21 changes: 13 additions & 8 deletions core/src/Revolution/modX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']
);
}
}
}
}
Expand Down
Loading