-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.php
More file actions
75 lines (62 loc) · 2.36 KB
/
bootstrap.php
File metadata and controls
75 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use App\Core\Support\Config;
use Dotenv\Dotenv;
// Load environment variables
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
Config::setBasePath(__DIR__);
// Error Logging Configuration
$logFile = __DIR__ . '/php_errors.log';
ini_set('log_errors', '1');
ini_set('error_log', $logFile);
$displayErrors = Config::get('app.debug', false) ? '1' : '0';
ini_set('display_errors', $displayErrors);
error_reporting(E_ALL);
// Ensure log file exists and is writable
if (!file_exists($logFile)) {
touch($logFile);
chmod($logFile, 0666);
}
$capsule = new Capsule;
try {
$connection = (string) Config::get('database.connection', 'sqlite');
$prefix = (string) Config::get('database.prefix', '');
if ($connection === 'sqlite') {
$dbPath = (string) Config::get('database.sqlite.database', 'database/database.sqlite');
if (!str_starts_with($dbPath, '/')) {
$dbPath = __DIR__ . '/' . ltrim($dbPath, '/');
}
if (!is_dir(dirname($dbPath))) {
mkdir(dirname($dbPath), 0755, true);
}
$capsule->addConnection([
'driver' => 'sqlite',
'database' => $dbPath,
'prefix' => $prefix,
]);
} else {
$capsule->addConnection([
'driver' => $connection,
'host' => (string) Config::get('database.mysql.host', '127.0.0.1'),
'port' => (string) Config::get('database.mysql.port', '3306'),
'database' => (string) Config::get('database.mysql.database', ''),
'username' => (string) Config::get('database.mysql.username', ''),
'password' => (string) Config::get('database.mysql.password', ''),
'charset' => (string) Config::get('database.mysql.charset', 'utf8mb4'),
'collation' => (string) Config::get('database.mysql.collation', 'utf8mb4_unicode_ci'),
'prefix' => $prefix,
]);
}
$capsule->setAsGlobal();
$capsule->bootEloquent();
} catch (\Exception $e) {
error_log("[TaskFlow Bootstrap Error] " . $e->getMessage());
if (php_sapi_name() === 'cli') {
echo "❌ Database Error: " . $e->getMessage() . "\n";
} else {
http_response_code(500);
die("Backend configuration error. Please check server logs.");
}
}