-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
57 lines (49 loc) · 1.88 KB
/
Copy pathbootstrap.php
File metadata and controls
57 lines (49 loc) · 1.88 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
<?php
/**
* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright (c) 2025 Md Mazharul Islam / Fluent-Themes
*/
// Safe Composer autoload guard for shared hosting
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) {
require __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
} else {
// Fallback PSR-4 autoloader for App\ namespace when vendor missing
if (is_dir(__DIR__ . DIRECTORY_SEPARATOR . 'app')) {
spl_autoload_register(function($class) {
if (strpos($class, 'App\\') === 0) {
$file = __DIR__ . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 4)) . '.php';
if (file_exists($file)) {
require_once $file;
}
}
});
}
}
// Now that autoloader is ready, add use statements
use App\Core\Env;
use App\Support\Database;
use App\Support\DatabaseMock;
use App\Support\Logger;
use App\Helpers\ModeHelper;
// Bootstrap PHP logging to storage/logs/app.log
$logDir = __DIR__ . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'logs';
if (!is_dir($logDir)) { @mkdir($logDir, 0775, true); }
error_reporting(E_ALL);
ini_set('log_errors','1');
ini_set('error_log', $logDir . DIRECTORY_SEPARATOR . 'app.log');
// Load env and define request-scoped mock mode
Env::load(__DIR__ . DIRECTORY_SEPARATOR . '.env');
$logger = Logger::create();
$logger->info('request', ['mode' => (ModeHelper::isMock() ? 'mock' : 'prod'), 'installed' => ModeHelper::isInstalled()]);
// Lazy database factory - only connects when called
$dbFactory = function() {
if (ModeHelper::shouldUseMockDB()) {
return DatabaseMock::create();
} else {
return Database::createSafe();
}
};
$GLOBALS['container'] = [
'logger' => $logger,
'db_factory' => $dbFactory,
];