summaryrefslogtreecommitdiff
path: root/lib/config.php
blob: 2f150bbf161fb91c248cf7ff376e77251436691c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
error_reporting(E_ERROR | E_PARSE);

$file_path = $_SERVER['DOCUMENT_ROOT'] . '/config.ini';

$c = parse_ini_file($file_path, true) ?: [];

define('DB_URL', $c['database']['url'] ?? null);
define('DB_USER', $c['database']['user'] ?? null);
define('DB_PASS', $c['database']['pass'] ?? null);

define('USERNAME_REGEX', $c['registration']['regex'] ?? '/^[a-zA-Z0-9_]+$/');

define('USERNAME_LENGTH', [
    intval($c['registration']['min_username_length']) ?: 8,
    intval($c['registration']['max_username_length']) ?: 20,
]);
define('PASSWORD_LENGTH', intval($c['registration']['min_password_length']) ?: 8);
define('USERNAME_ID_RANGE', [
    intval($c['registration']['min_id_length']) ?: 0,
    intval($c['registration']['max_id_length']) ?: PHP_INT_MAX
]);

define('IS_JSON_REQUEST', isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'application/json'));