ユーザー

This commit is contained in:
2025-12-07 20:23:29 +09:00
parent 4f70e6d4e4
commit d5428d7514
11 changed files with 476 additions and 2 deletions

View File

@@ -6,6 +6,24 @@ enum LogType {
case Csv;
}
class Result {
public bool $isSuccess;
public ?string $message;
public function __construct(bool $isSuccess, ?string $message = null) {
$this->isSuccess = $isSuccess;
$this->message = $message;
}
public static function Success(?string $message = null): self {
return new self(true, $message);
}
public static function Error(string $message): self {
return new self(false, $message);
}
}
function uuid(): string {
$data = random_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
@@ -90,4 +108,38 @@ function to_money($amount, $lang) {
default:
return '¥ '.number_format($amount, 0);
}
}
function randstr(): string {
srand(floor(time() / (60*60*24)));
$len = rand() % 20;
return bin2hex(random_bytes($len / 2));
}
function assert_null(mixed $assertion, Throwable|string|null $description = null): bool {
if (ini_get('zend.assertions') < 1) trigger_error('assert機能性が無効です。有効するには、php.iniで「zend.assertions = 1」に設定して下さい。', E_USER_WARNING);
if (is_null($assertion)) return true;
assert(false, $description ?? 'Assertion failed: value is not null');
return false;
}
function assert_not_null(mixed $assertion, Throwable|string|null $description = null): bool {
if (ini_get('zend.assertions') < 1) trigger_error('assert機能性が無効です。有効するには、php.iniで「zend.assertions = 1」に設定して下さい。', E_USER_WARNING);
if (!is_null($assertion)) return true;
assert(false, $description ?? 'Assertion failed: value is null');
return false;
}
function assert_unless_success(Result $assertion, Throwable|string|null $description = null): bool {
if (ini_get('zend.assertions') < 1) trigger_error('assert機能性が無効です。有効するには、php.iniで「zend.assertions = 1」に設定して下さい。', E_USER_WARNING);
if ($assertion->isSuccess) return true;
assert(false, $description ?? $assertion->message ?? 'Assertion failed: Result is not successful');
return false;
}
if (AUTH_ENABLED) {
function getcookie(string $name): string|null {
if (!$_COOKIE[$name]) return null;
return $_COOKIE[$name];
}
}