1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-01-22 11:23:45 +01:00

Merge pull request #862 from vichan-devel/5.2.0-74compatibility

5.2.0 PHP 7.4 compatibility
This commit is contained in:
Lorenzo Yario 2024-12-22 14:23:08 -06:00 committed by GitHub
commit 32f0cb3a5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 61 additions and 69 deletions

View File

@ -1,7 +1,6 @@
<?php
class Locks {
private static function filesystem(string $key): Lock|false {
private static function filesystem(string $key) {
$key = str_replace('/', '::', $key);
$key = str_replace("\0", '', $key);
@ -11,15 +10,14 @@ class Locks {
}
return new class($fd) implements Lock {
// Resources have no type in php.
private mixed $f;
// Resources have no type in PHP.
private $f;
function __construct($fd) {
public function __construct($fd) {
$this->f = $fd;
}
public function get(bool $nonblock = false): Lock|false {
public function get(bool $nonblock = false) {
$wouldblock = false;
flock($this->f, LOCK_SH | ($nonblock ? LOCK_NB : 0), $wouldblock);
if ($nonblock && $wouldblock) {
@ -28,7 +26,7 @@ class Locks {
return $this;
}
public function get_ex(bool $nonblock = false): Lock|false {
public function get_ex(bool $nonblock = false) {
$wouldblock = false;
flock($this->f, LOCK_EX | ($nonblock ? LOCK_NB : 0), $wouldblock);
if ($nonblock && $wouldblock) {
@ -37,33 +35,30 @@ class Locks {
return $this;
}
public function free(): Lock {
public function free() {
flock($this->f, LOCK_UN);
return $this;
}
};
}
/**
* No-op. Can be used for mocking.
*/
public static function none(): Lock|false {
public static function none() {
return new class() implements Lock {
public function get(bool $nonblock = false): Lock|false {
public function get(bool $nonblock = false) {
return $this;
}
public function get_ex(bool $nonblock = false): Lock|false {
public function get_ex(bool $nonblock = false) {
return $this;
}
public function free(): Lock {
public function free() {
return $this;
}
};
}
public static function get_lock(array $config, string $key): Lock|false {
public static function get_lock(array $config, string $key) {
if ($config['lock']['enabled'] == 'fs') {
return self::filesystem($key);
} else {
@ -73,12 +68,9 @@ class Locks {
}
interface Lock {
// Get a shared lock
public function get(bool $nonblock = false): Lock|false;
public function get(bool $nonblock = false);
// Get an exclusive lock
public function get_ex(bool $nonblock = false): Lock|false;
public function get_ex(bool $nonblock = false);
// Free a lock
public function free(): Lock;
public function free();
}

View File

@ -10,7 +10,7 @@ use Vichan\Functions\Net;
defined('TINYBOARD') or exit;
// create a hash/salt pair for validate logins
function mkhash(string $username, ?string $password, mixed $salt = false): array|string {
function mkhash(string $username, $password = null, $salt = false) {
global $config;
if (!$salt) {
@ -79,7 +79,7 @@ function calc_cookie_name(bool $is_https, bool $is_path_jailed, string $base_nam
}
}
function login(string $username, string $password): array|false {
function login(string $username, string $password) {
global $mod, $config;
$query = prepare("SELECT `id`, `type`, `boards`, `password`, `version` FROM ``mods`` WHERE BINARY `username` = :username");

View File

@ -73,7 +73,7 @@ class Queues {
};
}
public static function get_queue(array $config, string $name): Queue|false {
public static function get_queue(array $config, string $name) {
if (!isset(self::$queues[$name])) {
if ($config['queue']['enabled'] == 'fs') {
$lock = Locks::get_lock($config, $name);