Commit 335cde0c authored by Administrator's avatar Administrator

Update 1 files via Son of Anton

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