szurubooru/src/Bootstrap.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2013-10-05 17:12:51 +02:00
<?php
class Bootstrap
{
public function workWrapper($workCallback)
{
2013-10-05 19:24:08 +02:00
$this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/';
2013-10-05 17:12:51 +02:00
session_start();
2013-10-05 19:24:08 +02:00
2013-10-12 22:37:18 +02:00
$this->context->handleExceptions = false;
LayoutHelper::setTitle($this->config->main->title);
2013-10-28 11:19:15 +01:00
$this->context->json = isset($_GET['json']);
$this->context->layoutName = $this->context->json
2013-10-05 17:12:51 +02:00
? 'layout-json'
: 'layout-normal';
$this->context->transport = new StdClass;
2013-11-16 18:40:26 +01:00
StatusHelper::init();
2013-10-05 17:12:51 +02:00
AuthController::doLogIn();
2013-10-05 19:24:08 +02:00
2013-10-05 17:12:51 +02:00
if (empty($this->context->route))
{
$this->context->viewName = 'error-404';
(new \Chibi\View())->renderFile($this->context->layoutName);
return;
}
try
{
if ($this->context->layoutName == 'layout-normal')
{
ob_start(['LayoutHelper', 'transformHtml']);
$workCallback();
ob_end_flush();
}
else
$workCallback();
2013-10-05 17:12:51 +02:00
}
catch (\Chibi\MissingViewFileException $e)
{
$this->context->json = true;
$this->context->layoutName = 'layout-json';
(new \Chibi\View())->renderFile($this->context->layoutName);
}
2013-11-16 18:40:26 +01:00
catch (SimpleException $e)
{
StatusHelper::failure(rtrim($e->getMessage(), '.') . '.');
if (!$this->context->handleExceptions)
$this->context->viewName = 'message';
(new \Chibi\View())->renderFile($this->context->layoutName);
}
2013-10-05 17:12:51 +02:00
catch (Exception $e)
{
2013-11-16 18:40:26 +01:00
StatusHelper::failure(rtrim($e->getMessage(), '.') . '.');
$this->context->transport->exception = $e;
$this->context->transport->queries = Database::getLogs();
2013-10-05 17:12:51 +02:00
$this->context->viewName = 'error-exception';
(new \Chibi\View())->renderFile($this->context->layoutName);
}
2013-10-30 23:24:27 +01:00
AuthController::observeWorkFinish();
2013-10-05 17:12:51 +02:00
}
}