Skip to content

Commit bc81dea

Browse files
authored
Merge pull request #6509 from WoltLab/6.2-file-util
Remove obsolete member variables from `FileUtil`
2 parents f24376a + 668b004 commit bc81dea

1 file changed

Lines changed: 23 additions & 36 deletions

File tree

wcfsetup/install/files/lib/util/FileUtil.class.php

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,12 @@
1010
/**
1111
* Contains file-related functions.
1212
*
13-
* @author Marcel Werk
14-
* @copyright 2001-2019 WoltLab GmbH
15-
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @author Marcel Werk
14+
* @copyright 2001-2025 WoltLab GmbH
15+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1616
*/
1717
final class FileUtil
1818
{
19-
/**
20-
* finfo instance
21-
*/
22-
protected static \finfo $finfo;
23-
24-
/**
25-
* memory limit in bytes
26-
*/
27-
protected static int $memoryLimit;
28-
29-
/**
30-
* chmod mode
31-
* @var string
32-
*/
33-
protected static $mode;
34-
3519
/**
3620
* A regular expression that allows to detect links within text.
3721
*/
@@ -422,13 +406,14 @@ public static function isApacheModule(): bool
422406
*/
423407
public static function getMimeType(string $filename): string
424408
{
425-
if (!isset(self::$finfo)) {
426-
self::$finfo = new \finfo(\FILEINFO_MIME_TYPE);
409+
static $finfo = null;
410+
if ($finfo === null) {
411+
$finfo = new \finfo(\FILEINFO_MIME_TYPE);
427412
}
428413

429414
// \finfo->file() can fail for files that contain only 1 byte, because libmagic expects at least
430415
// a few bytes in order to determine the type. See https://bugs.php.net/bug.php?id=64684
431-
$mimeType = @self::$finfo->file($filename);
416+
$mimeType = @$finfo->file($filename);
432417

433418
return $mimeType ?: 'application/octet-stream';
434419
}
@@ -445,19 +430,20 @@ public static function makeWritable(string $filename): void
445430
return;
446431
}
447432

448-
if (self::$mode === null) {
433+
static $mode = null;
434+
if ($mode === null) {
449435
// WCFSetup
450436
if (\defined('INSTALL_SCRIPT') && \file_exists(INSTALL_SCRIPT)) {
451437
// do not use PHP_OS here, as this represents the system it was built on != running on
452438
// php_uname() is forbidden on some strange hosts; PHP_EOL is reliable
453439
if (\PHP_EOL == "\r\n") {
454440
// Windows
455-
self::$mode = '0777';
441+
$mode = '0777';
456442
} else {
457443
// anything but Windows
458444
\clearstatcache();
459445

460-
self::$mode = '0666';
446+
$mode = '0666';
461447

462448
$tmpFilename = '__permissions_' . \sha1((string)\time()) . '.txt';
463449
@\touch($tmpFilename);
@@ -470,7 +456,7 @@ public static function makeWritable(string $filename): void
470456
$fileOwner = \fileowner($tmpFilename);
471457

472458
if ($scriptOwner === $fileOwner) {
473-
self::$mode = '0644';
459+
$mode = '0644';
474460
}
475461

476462
@\unlink($tmpFilename);
@@ -482,18 +468,18 @@ public static function makeWritable(string $filename): void
482468
throw new SystemException("Unable to find 'wcf/lib/system/WCF.class.php'.");
483469
}
484470

485-
self::$mode = '0' . \substr(\sprintf('%o', \fileperms(WCF_DIR . 'lib/system/WCF.class.php')), -3);
471+
$mode = '0' . \substr(\sprintf('%o', \fileperms(WCF_DIR . 'lib/system/WCF.class.php')), -3);
486472
}
487473
}
488474

489475
if (\is_dir($filename)) {
490-
if (self::$mode == '0644') {
476+
if ($mode == '0644') {
491477
@\chmod($filename, 0755);
492478
} else {
493479
@\chmod($filename, 0777);
494480
}
495481
} else {
496-
@\chmod($filename, \octdec(self::$mode));
482+
@\chmod($filename, \octdec($mode));
497483
}
498484

499485
if (!\is_writable($filename)) {
@@ -507,20 +493,21 @@ public static function makeWritable(string $filename): void
507493
*/
508494
public static function getMemoryLimit(): int
509495
{
510-
if (!isset(self::$memoryLimit)) {
511-
self::$memoryLimit = 0;
496+
static $memoryLimit = null;
512497

513-
$memoryLimit = \ini_get('memory_limit');
498+
if ($memoryLimit === null) {
499+
$memoryLimit = 0;
500+
$iniMemoryLimit = \ini_get('memory_limit');
514501

515502
// no limit
516-
if ($memoryLimit == "-1") {
517-
self::$memoryLimit = -1;
503+
if ($iniMemoryLimit == "-1") {
504+
$memoryLimit = -1;
518505
} else {
519-
self::$memoryLimit = \ini_parse_quantity($memoryLimit);
506+
$memoryLimit = \ini_parse_quantity($iniMemoryLimit);
520507
}
521508
}
522509

523-
return self::$memoryLimit;
510+
return $memoryLimit;
524511
}
525512

526513
/**

0 commit comments

Comments
 (0)