Commit 335cde0c authored by Administrator's avatar Administrator

Update 1 files via Son of Anton

parent 56b6d45d
......@@ -36,31 +36,18 @@ final class App
return $this;
}
// Set timezone
date_default_timezone_set('Africa/Cairo');
// Load .env
$this->loadEnv();
// Load config files
$this->loadConfig();
// Initialize error handler
ExceptionHandler::register();
// Initialize database
$this->initDatabase();
// Initialize session
$this->initSession();
// Load DB config overrides
$this->loadDbConfigOverrides();
// Auto-discover and load module bootstraps
$this->loadModuleBootstraps();
// Auto-discover and load module routes
$this->router = new Router();
$this->loadModuleRoutes();
......@@ -151,18 +138,14 @@ final class App
$value = json_decode($value, true) ?? $value;
break;
}
// Store as dot notation override
$this->config['db_overrides'][$row['config_key']] = $value;
}
} catch (\Throwable $e) {
// DB might not be ready yet — ignore
// DB might not be ready yet
}
}
/**
* Auto-discover and require all Modules/*/bootstrap.php files.
* This is where modules register their menu items, permissions, event listeners, etc.
*/
// Load all module bootstrap files
private function loadModuleBootstraps(): void
{
$modulesDir = $this->basePath . '/app/Modules';
......@@ -170,12 +153,13 @@ final class App
return;
}
$bootstrapFiles = glob($modulesDir . '/*/bootstrap.php');
$pattern = $modulesDir . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'bootstrap.php';
$bootstrapFiles = glob($pattern);
if ($bootstrapFiles === false) {
return;
}
sort($bootstrapFiles); // Alphabetical order for deterministic loading
sort($bootstrapFiles);
foreach ($bootstrapFiles as $file) {
try {
......@@ -186,9 +170,7 @@ final class App
}
}
/**
* Auto-discover and merge all Modules/*/Routes.php files.
*/
// Load all module route files
private function loadModuleRoutes(): void
{
$modulesDir = $this->basePath . '/app/Modules';
......@@ -196,7 +178,8 @@ final class App
return;
}
$routeFiles = glob($modulesDir . '/*/Routes.php');
$pattern = $modulesDir . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'Routes.php';
$routeFiles = glob($pattern);
if ($routeFiles === false) {
return;
}
......@@ -210,11 +193,11 @@ final class App
foreach ($routes as $route) {
if (is_array($route) && count($route) >= 3) {
$this->router->addRoute(
$route[0], // method
$route[1], // path
$route[2], // controller@action
$route[3] ?? [], // middleware
$route[4] ?? null // permission
$route[0],
$route[1],
$route[2],
$route[3] ?? [],
$route[4] ?? null
);
}
}
......@@ -225,8 +208,6 @@ final class App
}
}
// ── Accessors ──
public function db(): Database
{
return $this->db;
......@@ -248,12 +229,10 @@ final class App
return $this->config;
}
// Check DB overrides first
if (isset($this->config['db_overrides'][$key])) {
return $this->config['db_overrides'][$key];
}
// Dot notation: 'app.name' → $this->config['app']['name']
$parts = explode('.', $key);
$value = $this->config;
......@@ -283,7 +262,10 @@ final class App
return $this->basePath . '/storage';
}
// ── Employee Context ──
public function isDebug(): bool
{
return (bool) $this->config('app.debug', false);
}
public function setCurrentEmployee(object $employee): void
{
......@@ -305,8 +287,6 @@ final class App
return $this->currentBranch;
}
// ── Simple Service Container ──
public function bind(string $key, $value): void
{
$this->bindings[$key] = $value;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment