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;
|
2013-10-05 21:22:28 +02:00
|
|
|
$this->context->title = $this->config->main->title;
|
2013-10-09 21:02:54 +02:00
|
|
|
$this->context->stylesheets =
|
|
|
|
[
|
2013-10-09 21:31:38 +02:00
|
|
|
'../lib/jquery-ui/jquery-ui.css',
|
2013-10-09 21:02:54 +02:00
|
|
|
'core.css',
|
|
|
|
];
|
|
|
|
$this->context->scripts =
|
|
|
|
[
|
|
|
|
'../lib/jquery/jquery.min.js',
|
2013-10-09 21:31:38 +02:00
|
|
|
'../lib/jquery-ui/jquery-ui.min.js',
|
2013-10-25 15:41:09 +02:00
|
|
|
'../lib/mousetrap/mousetrap.min.js',
|
2013-10-09 21:31:38 +02:00
|
|
|
'core.js',
|
2013-10-09 21:02:54 +02:00
|
|
|
];
|
2013-10-05 22:52:55 +02:00
|
|
|
|
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;
|
|
|
|
$this->context->transport->success = null;
|
|
|
|
|
2013-10-27 20:39:32 +01: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
|
|
|
|
{
|
|
|
|
$workCallback();
|
|
|
|
}
|
2013-10-05 21:24:20 +02:00
|
|
|
catch (SimpleException $e)
|
|
|
|
{
|
|
|
|
$this->context->transport->errorMessage = rtrim($e->getMessage(), '.') . '.';
|
2013-10-19 15:19:47 +02:00
|
|
|
$this->context->transport->errorHtml = TextHelper::parseMarkdown($this->context->transport->errorMessage, true);
|
2013-10-05 21:24:20 +02:00
|
|
|
$this->context->transport->exception = $e;
|
|
|
|
$this->context->transport->success = false;
|
2013-10-12 22:37:18 +02:00
|
|
|
if (!$this->context->handleExceptions)
|
|
|
|
$this->context->viewName = 'error-simple';
|
2013-10-06 13:22:58 +02:00
|
|
|
(new \Chibi\View())->renderFile($this->context->layoutName);
|
2013-10-05 21:24:20 +02:00
|
|
|
}
|
2013-10-05 17:12:51 +02:00
|
|
|
catch (Exception $e)
|
|
|
|
{
|
2013-10-06 19:53:33 +02:00
|
|
|
$this->context->transport->errorMessage = rtrim($e->getMessage(), '.') . '.';
|
2013-10-19 15:19:47 +02:00
|
|
|
$this->context->transport->errorHtml = TextHelper::parseMarkdown($this->context->transport->errorMessage, true);
|
2013-10-06 19:53:33 +02:00
|
|
|
$this->context->transport->exception = $e;
|
2013-10-30 20:20:01 +01:00
|
|
|
$this->context->transport->queries = array_map(function($x) { return preg_replace('/\s+/', ' ', $x); }, queryLogger()->getLogs());
|
2013-10-06 19:53:33 +02:00
|
|
|
$this->context->transport->success = false;
|
2013-10-05 17:12:51 +02:00
|
|
|
$this->context->viewName = 'error-exception';
|
|
|
|
(new \Chibi\View())->renderFile($this->context->layoutName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|