Use PHP_OS_FAMILY instead of substr(PHP_OS,0,3) for Windows checks

This is new in PHP 7.2, and has a documented set of values at
<https://www.php.net/manual/en/reserved.constants.php>.

Change-Id: If732a652f091c26d7d645766ba6e76fbf464f755
This commit is contained in:
Timo Tijhof 2020-06-13 19:54:36 +01:00 committed by Reedy
parent c0efb9f0af
commit b547aa6396
5 changed files with 7 additions and 11 deletions

View file

@ -1841,11 +1841,7 @@ function wfTimestampNow() {
* @return bool True if it's Windows, false otherwise.
*/
function wfIsWindows() {
static $isWindows = null;
if ( $isWindows === null ) {
$isWindows = strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';
}
return $isWindows;
return PHP_OS_FAMILY === 'Windows';
}
/**

View file

@ -77,7 +77,7 @@ class FSFileBackend extends FileBackendStore {
/** @var string Required OS username to own files */
protected $fileOwner;
/** @var bool Simpler version of PHP_OS_FAMILY (PHP 7.2) */
/** @var bool Simpler version of PHP_OS_FAMILY */
protected $os;
/** @var string OS username running this script */
protected $currentUser;
@ -98,9 +98,9 @@ class FSFileBackend extends FileBackendStore {
public function __construct( array $config ) {
parent::__construct( $config );
if ( substr( PHP_OS, 0, 3 ) === 'WIN' || PHP_OS === 'Windows' ) {
if ( PHP_OS_FAMILY === 'Windows' ) {
$this->os = 'Windows';
} elseif ( substr( PHP_OS, 0, -3 ) === 'BSD' || PHP_OS === 'Darwin' ) {
} elseif ( PHP_OS_FAMILY === 'BSD' || PHP_OS_FAMILY === 'Darwin' ) {
$this->os = 'BSD';
} else {
$this->os = 'Linux';

View file

@ -92,7 +92,7 @@ class TempFSFile extends FSFile {
// the current process.
// The user is included as if various scripts are run by different users they will likely
// not be able to access each others temporary files.
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
if ( PHP_OS_FAMILY === 'Windows' ) {
$tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp-' . get_current_user();
if ( !is_dir( $tmp ) ) {
mkdir( $tmp );

View file

@ -60,7 +60,7 @@ class FSLockManager extends LockManager {
parent::__construct( $config );
$this->lockDir = $config['lockDirectory'];
$this->isWindows = ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' );
$this->isWindows = ( PHP_OS_FAMILY === 'Windows' );
}
/**

View file

@ -645,7 +645,7 @@ class GlobalIdGenerator {
// Try to get some ID that uniquely identifies this machine (RFC 4122)...
if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
AtEase::suppressWarnings();
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
if ( PHP_OS_FAMILY === 'Windows' ) {
// https://technet.microsoft.com/en-us/library/bb490913.aspx
$csv = trim( ( $this->shellCallback )( 'getmac /NH /FO CSV' ) );
$line = substr( $csv, 0, strcspn( $csv, "\n" ) );