summaryrefslogtreecommitdiff
path: root/lib/config.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/config.php')
-rw-r--r--lib/config.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/config.php b/lib/config.php
new file mode 100644
index 0000000..2f150bb
--- /dev/null
+++ b/lib/config.php
@@ -0,0 +1,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')); \ No newline at end of file