/** * Bootstrap method */ public function bootstrap() { // Start the rudimental system try { // Load settingsfile $this->loadSettings(); // From here starts output buffering ob_start(); // Registe PSR classloader $this->registerClassloader(); // Create core DI container instance and map the instance to comntainer $this->di = \Core\DI\DI::getInstance(); $this->di->mapValue('core.di', $this->di); $this->initLogger(); // Run inits $this->initDatabase(); $this->initMessageHandler(); $this->initDependencies(); $this->initHttp(); $this->initSession(); $this->initConfig(); $this->initMailer(); $this->initRouter(); // Get an instance of Core app $this->getAppInstance('Core'); $this->initSecurity(); $this->initPage(); $this->initAssetManager(); // Run highlevel system $this->autodiscoverApps(); // Match request against the generic routes to get the ajax request flag and to match a fallback result. $this->router->match(); // Initiate apps $this->initApps(); // Match routes again as now possible app routes are available $this->router->match(); // Run dispatcher $result = $this->dispatch(); // Send mails $this->mailer->send(); // Process all assets $this->processAssets(); // Send cookies $this->http->cookies->send(); // Redirect requested? if (!empty($_SESSION['Core']['redirect'])) { $this->http->header->location($_SESSION['Core']['redirect']['location'], $_SESSION['Core']['redirect']['permanent']); $this->http->header->send(); // Important: Clear redirect from session! unset($_SESSION['Core']['redirect']); return; } switch ($this->router->getFormat()) { case 'file': $sendfile = new Sendfile($result); $sendfile->send(); break; case 'html': $this->http->header->contentType('text/html', 'utf-8'); $language = $this->getAppInstance('Core')->language; // Add logoff button for logged in users if ($this->user->isGuest()) { $this->page->menu->createItem('register', $language->get('menu.register'), $this->router->generate('core.register')); $this->page->menu->createItem('login', $language->get('menu.login'), $this->router->generate('core.login', ['action' => 'login'])); } else { $usermenu = $this->page->menu->createItem('login', $this->user->getDisplayname()); // Show admin menu? if ($this->user->getAdmin()) { $usermenu->createItem('admin', $language->get('menu.admin'), $this->router->generate('core.admin')); } $usermenu->createItem('logout', $language->get('menu.logout'), $this->router->generate('core.login', ['action' => 'logout'])); } $this->page->setHome($this->config->get('Core', 'url.home')); $this->page->setContent($result); $result = $this->page->render(); } // Send headers so far $this->http->header->send(); } catch (\Throwable $t) { $error = new ErrorHandler($t); $error->setAjax(isset($_REQUEST['ajax'])); $error->setPublic(isset($this->user) && $this->user->getAdmin()); $error->setPublic(true); if (isset($this->logger)) { $error->setLogger($this->logger); } http_response_code(500); $result = $error->handle(); } echo $result; ob_end_flush(); }