This commit is contained in:
Marcin Kurczewski 2014-02-05 08:22:26 +01:00
parent 91b0432067
commit 6a407fc87a

View file

@ -1,6 +1,28 @@
<?php <?php
class Bootstrap class Bootstrap
{ {
public function render($callback = null)
{
if ($callback === null)
{
$callback = function()
{
(new \Chibi\View())->renderFile($this->context->layoutName);
};
}
if ($this->context->layoutName == 'layout-normal')
{
ob_start(['LayoutHelper', 'transformHtml']);
$callback();
ob_end_flush();
}
else
{
$callback();
}
}
public function workWrapper($workCallback) public function workWrapper($workCallback)
{ {
$this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/'; $this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/';
@ -21,33 +43,26 @@ class Bootstrap
if (empty($this->context->route)) if (empty($this->context->route))
{ {
$this->context->viewName = 'error-404'; $this->context->viewName = 'error-404';
(new \Chibi\View())->renderFile($this->context->layoutName); $this->render();
return; return;
} }
try try
{ {
if ($this->context->layoutName == 'layout-normal') $this->render($workCallback);
{
ob_start(['LayoutHelper', 'transformHtml']);
$workCallback();
ob_end_flush();
}
else
$workCallback();
} }
catch (\Chibi\MissingViewFileException $e) catch (\Chibi\MissingViewFileException $e)
{ {
$this->context->json = true; $this->context->json = true;
$this->context->layoutName = 'layout-json'; $this->context->layoutName = 'layout-json';
(new \Chibi\View())->renderFile($this->context->layoutName); $this->render();
} }
catch (SimpleException $e) catch (SimpleException $e)
{ {
StatusHelper::failure(rtrim($e->getMessage(), '.') . '.'); StatusHelper::failure(rtrim($e->getMessage(), '.') . '.');
if (!$this->context->handleExceptions) if (!$this->context->handleExceptions)
$this->context->viewName = 'message'; $this->context->viewName = 'message';
(new \Chibi\View())->renderFile($this->context->layoutName); $this->render();
} }
catch (Exception $e) catch (Exception $e)
{ {
@ -55,7 +70,7 @@ class Bootstrap
$this->context->transport->exception = $e; $this->context->transport->exception = $e;
$this->context->transport->queries = Database::getLogs(); $this->context->transport->queries = Database::getLogs();
$this->context->viewName = 'error-exception'; $this->context->viewName = 'error-exception';
(new \Chibi\View())->renderFile($this->context->layoutName); $this->render();
} }
AuthController::observeWorkFinish(); AuthController::observeWorkFinish();