|
@ -1,4 +1,4 @@ |
|
|
<?php |
|
|
|
|
|
|
|
|
<?php namespace Majestic\App; |
|
|
/** |
|
|
/** |
|
|
* @copyright NetMonsters <team@netmonsters.ru> |
|
|
* @copyright NetMonsters <team@netmonsters.ru> |
|
|
* @link http://netmonsters.ru |
|
|
* @link http://netmonsters.ru |
|
@ -10,14 +10,14 @@ |
|
|
class FrontController |
|
|
class FrontController |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* @var Router |
|
|
|
|
|
|
|
|
* @var Router\Router |
|
|
*/ |
|
|
*/ |
|
|
protected $router; |
|
|
protected $router; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @var string |
|
|
* @var string |
|
|
*/ |
|
|
*/ |
|
|
protected $view = 'PHPView'; |
|
|
|
|
|
|
|
|
protected $view = '\Majestic\View\PHPView'; |
|
|
|
|
|
|
|
|
protected $base_url = ''; |
|
|
protected $base_url = ''; |
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ class FrontController |
|
|
private function __construct() |
|
|
private function __construct() |
|
|
{ |
|
|
{ |
|
|
// ErrorHandler::init();
|
|
|
// ErrorHandler::init();
|
|
|
$this->router = new Router(); |
|
|
|
|
|
|
|
|
$this->router = new Router\Router(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -69,12 +69,12 @@ class FrontController |
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @param null $view |
|
|
* @param null $view |
|
|
* @return PHPView |
|
|
|
|
|
|
|
|
* @return ..\View\PHPView |
|
|
*/ |
|
|
*/ |
|
|
public function getView($view = null) |
|
|
public function getView($view = null) |
|
|
{ |
|
|
{ |
|
|
$view = ($view) ? $view : $this->view; |
|
|
$view = ($view) ? $view : $this->view; |
|
|
return new $view(Config::get($view)); |
|
|
|
|
|
|
|
|
return new $view(\Majestic\Config::get($view)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -93,7 +93,7 @@ class FrontController |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @return Router |
|
|
|
|
|
|
|
|
* @return Router\Router |
|
|
*/ |
|
|
*/ |
|
|
public function getRouter() |
|
|
public function getRouter() |
|
|
{ |
|
|
{ |
|
@ -103,53 +103,53 @@ class FrontController |
|
|
public function execute() |
|
|
public function execute() |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
$request = Env::getRequestUri(true); |
|
|
|
|
|
|
|
|
$request = \Majestic\Env::getRequestUri(true); |
|
|
$route = $this->getRouter()->route($request); |
|
|
$route = $this->getRouter()->route($request); |
|
|
if (!$route) { |
|
|
if (!$route) { |
|
|
throw new Error404Exception('Route for "' . $request . '" not found'); |
|
|
|
|
|
|
|
|
throw new \Majestic\Exception\Error404Exception('Route for "' . $request . '" not found'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$action_class = $route->getAction(); |
|
|
$action_class = $route->getAction(); |
|
|
if (!class_exists($action_class)) { |
|
|
if (!class_exists($action_class)) { |
|
|
throw new GeneralException('Action class "' . $action_class . '" not found.'); |
|
|
|
|
|
|
|
|
throw new \Majestic\Exception\GeneralException('Action class "' . $action_class . '" not found.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$action = new $action_class(); |
|
|
$action = new $action_class(); |
|
|
$layout_class = $route->getLayout(); |
|
|
$layout_class = $route->getLayout(); |
|
|
if (!class_exists($layout_class)) { |
|
|
if (!class_exists($layout_class)) { |
|
|
throw new GeneralException('Layout class "' . $layout_class . '" not found.'); |
|
|
|
|
|
|
|
|
throw new \Majestic\Exception\GeneralException('Layout class "' . $layout_class . '" not found.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @var Layout $layout |
|
|
|
|
|
|
|
|
* @var \Majestic\Layout\Layout $layout |
|
|
*/ |
|
|
*/ |
|
|
$layout = new $layout_class(); |
|
|
$layout = new $layout_class(); |
|
|
$html = $layout->fetch($action); |
|
|
$html = $layout->fetch($action); |
|
|
if (Config::get('PROFILER')) { |
|
|
|
|
|
|
|
|
if (\Majestic\Config::get('PROFILER')) { |
|
|
if (is_subclass_of($action, 'AjaxAction')) { |
|
|
if (is_subclass_of($action, 'AjaxAction')) { |
|
|
Profiler::getInstance()->getJson(); |
|
|
|
|
|
|
|
|
\Majestic\Util\Profiler\Profiler::getInstance()->getJson(); |
|
|
} else { |
|
|
} else { |
|
|
$html = Profiler::getInstance()->end($html); |
|
|
|
|
|
|
|
|
$html = \Majestic\Util\Profiler\Profiler::getInstance()->end($html); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $html; |
|
|
return $html; |
|
|
} |
|
|
} |
|
|
catch (Exception $e) { |
|
|
|
|
|
if (Config::get('DEBUG')) { |
|
|
|
|
|
|
|
|
catch (\Exception $e) { |
|
|
|
|
|
if (\Majestic\Config::get('DEBUG')) { |
|
|
if (!headers_sent()) { |
|
|
if (!headers_sent()) { |
|
|
if ($e instanceof ErrorHTTPException) { |
|
|
|
|
|
|
|
|
if ($e instanceof \Majestic\Exception\ErrorHTTPException) { |
|
|
header($e->getHTTPHeader()); |
|
|
header($e->getHTTPHeader()); |
|
|
} else { |
|
|
} else { |
|
|
header('HTTP/1.0 500 Internal Server Error'); |
|
|
header('HTTP/1.0 500 Internal Server Error'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
ErrorHandler::logError($e); |
|
|
|
|
|
return ErrorHandler::showDebug($e); |
|
|
|
|
|
|
|
|
\Majestic\Exception\ErrorHandler::logError($e); |
|
|
|
|
|
return \Majestic\Exception\ErrorHandler::showDebug($e); |
|
|
} |
|
|
} |
|
|
$layout_class = $this->getRouter()->getErrorLayout(); |
|
|
$layout_class = $this->getRouter()->getErrorLayout(); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @var ErrorLayout $layout |
|
|
|
|
|
|
|
|
* @var \Majestic\Layout\ErrorLayout $layout |
|
|
*/ |
|
|
*/ |
|
|
$layout = new $layout_class(); |
|
|
$layout = new $layout_class(); |
|
|
$layout->setException($e); |
|
|
$layout->setException($e); |