Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | use Lucent\Facades\FileSystem; |
| 4 | |
| 5 | $pharPath = Phar::running(false); |
| 6 | $pharActive = !empty($pharPath); |
| 7 | |
| 8 | // Load framework from .phar (PRODUCTION) or source (DEVELOPMENT/TESTS) |
| 9 | if ($pharActive) { |
| 10 | define("ROOT", Phar::running() . DIRECTORY_SEPARATOR); |
| 11 | $runningLocation = dirname($pharPath, 2) . DIRECTORY_SEPARATOR; |
| 12 | $phar = new Phar($pharPath); |
| 13 | $metadata = $phar->getMetadata(); |
| 14 | define("VERSION", is_string($metadata['version']) ? $metadata['version'] : 'unknown'); |
| 15 | } else { |
| 16 | define("ROOT", __DIR__ . DIRECTORY_SEPARATOR); |
| 17 | $runningLocation = dirname(__DIR__) . DIRECTORY_SEPARATOR . "temp_install" . DIRECTORY_SEPARATOR; |
| 18 | define("VERSION", 'v0.' . date('ymd') . '.local'); |
| 19 | } |
| 20 | |
| 21 | // Define constants |
| 22 | define("RUNNING_LOCATION", $runningLocation); |
| 23 | define("LUCENT", ROOT . "Lucent" . DIRECTORY_SEPARATOR); |
| 24 | |
| 25 | // Set file system root |
| 26 | require_once LUCENT . "Facades" . DIRECTORY_SEPARATOR . "FileSystem.php"; |
| 27 | FileSystem::overrideRootPath(RUNNING_LOCATION); |
| 28 | |
| 29 | define("PACKAGES_ROOT", FileSystem::rootPath() . "packages" . DIRECTORY_SEPARATOR); |
| 30 | define("APP", FileSystem::rootPath() . "App" . DIRECTORY_SEPARATOR); |
| 31 | |
| 32 | // Include Composer autoloader if available |
| 33 | $composerAutoloader = PACKAGES_ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; |
| 34 | if (file_exists($composerAutoloader)) { |
| 35 | require_once $composerAutoloader; |
| 36 | } |
| 37 | |
| 38 | // Import database constants |
| 39 | require_once LUCENT . "Database" . DIRECTORY_SEPARATOR . "constants.php"; |
| 40 | |
| 41 | // Register PSR-0 autoloader |
| 42 | spl_autoload_register(function ($class) use ($pharActive, $pharPath) { |
| 43 | // Determine base path based on namespace |
| 44 | if (str_starts_with($class, 'Lucent\\')) { |
| 45 | $basePath = $pharActive ? "phar://$pharPath" : __DIR__; |
| 46 | } else { |
| 47 | $basePath = FileSystem::rootPath(); |
| 48 | } |
| 49 | |
| 50 | // Convert namespace to file path |
| 51 | $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; |
| 52 | $fullPath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file; |
| 53 | |
| 54 | // Attempt to load the file |
| 55 | if (file_exists($fullPath)) { |
| 56 | require_once $fullPath; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | // Log error in development only |
| 61 | if (!$pharActive) { |
| 62 | error_log("Autoloader: File not found at: " . $fullPath); |
| 63 | } |
| 64 | |
| 65 | return false; |
| 66 | }); |
| 67 | |
| 68 | // Class aliases for backwards compatibility |
| 69 | class_alias('Lucent\Model\Model', 'Lucent\Model'); |
| 70 | class_alias('Lucent\Model\Collection', 'Lucent\ModelCollection'); |