Files
desktop/docs/Umsetzungsanweisung/Old-Nexus/src/App/App.php
Lars Gebhardt-Kusche 2cdd14c400
All checks were successful
Deploy / deploy-staging (push) Successful in 24s
Deploy / deploy-production (push) Has been skipped
deploy
2026-06-20 01:50:07 +02:00

78 lines
2.7 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App;
final class App
{
private static ?self $instance = null;
private Request $request;
private SessionManager $session;
private Assets $assets;
private I18n $i18n;
private Flash $flash;
private ?\PDO $pdo;
private ?\PDO $basePdo;
private ModuleManager $modules;
private AuthService $auth;
private NexusDashboardService $dashboards;
private function __construct(private Config $config)
{
$this->request = new Request();
$this->session = new SessionManager($config);
$this->assets = new Assets($config);
$this->i18n = new I18n($config, 'en');
$this->flash = new Flash($this->session);
$this->pdo = Database::createPdo($config);
$this->basePdo = Database::createBasePdo($config);
$modulesPath = $this->config->modulesPath;
if ($modulesPath === '' || !is_dir($modulesPath)) {
$candidates = [
__DIR__ . '/../../modules',
__DIR__ . '/../modules',
dirname(__DIR__, 3) . '/modules',
];
foreach ($candidates as $candidate) {
if (is_dir($candidate)) {
$modulesPath = $candidate;
break;
}
}
}
$this->modules = new ModuleManager($this->basePdo, $modulesPath);
$this->modules->bootEnabled();
$this->auth = new AuthService($this);
$this->dashboards = new NexusDashboardService($this->basePdo);
}
public static function init(Config $config): self
{
if (self::$instance === null) {
self::$instance = new self($config);
}
return self::$instance;
}
public static function get(): self
{
if (self::$instance === null) {
throw new \RuntimeException('App not initialized. Call App::init() in bootstrap.');
}
return self::$instance;
}
public function config(): Config { return $this->config; }
public function request(): Request { return $this->request; }
public function session(): SessionManager { return $this->session; }
public function assets(): Assets { return $this->assets; }
public function i18n(): I18n { return $this->i18n; }
public function flash(): Flash { return $this->flash; }
public function pdo(): ?\PDO { return $this->pdo; }
public function basePdo(): ?\PDO { return $this->basePdo; }
public function modules(): ModuleManager { return $this->modules; }
public function auth(): AuthService { return $this->auth; }
public function dashboards(): NexusDashboardService { return $this->dashboards; }
}