Dragon-Knight/public/install.php
2025-08-15 09:34:27 -04:00

63 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is a part of the Dragon-Knight project.
*
* Copyright (c) 2024-present Sharkk
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/
namespace DragonKnight;
use DragonKnight\Actions\Install;
ini_set('display_errors', 1);
error_reporting(E_ALL);
set_time_limit(0);
ignore_user_abort(true);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '-1'); // Unlimited memory usage
function loadEnv(string $filePath = __DIR__.'/../.env'): void
{
if (! file_exists($filePath)) {
throw new \Exception('The .env file does not exist.');
}
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$trimmedLines = array_map('trim', $lines);
$filteredLines = array_filter($trimmedLines, fn ($line) => $line && ! str_starts_with($line, '#'));
array_walk($filteredLines, function ($line) {
[$name, $value] = array_map('trim', explode('=', $line, 2));
if (! array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
}
});
}
loadEnv(__DIR__.'/../../.env');
if (! $autoloader = require file_exists(__DIR__.'/../vendor/autoload.php') ? __DIR__.'/../vendor/autoload.php' : __DIR__.'/../../autoload.php') {
throw new \Exception('Composer autoloader not found. Run `composer install` and try again.');
}
if (! extension_loaded('sqlite3')) {
throw new \Exception('The SQLite3 extension is required but not loaded. Please enable it in your PHP configuration.');
}
Install::second();
Install::fourth([
'username' => 'admin',
'email' => 'admin@example.com',
'confirm_email' => 'admin@example.com',
'password' => 'password',
'confirm_password' => 'password',
'charclass' => '1', // [1 => 'Mage', 2 => 'Warrior', 3 => 'Paladin']
]);
Install::fifth();