Errors and exceptions handling, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@121 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
pzinovkin
2010-03-07 17:26:44 +00:00
parent 2d7f5391f8
commit 4f7e5b00bc
7 changed files with 305 additions and 82 deletions

View File

@ -21,11 +21,6 @@ class FrontController
*/
protected $view = 'PHPView';
/**
* @var string
*/
protected $view_path;
protected $base_url = '';
/**
@ -36,9 +31,13 @@ class FrontController
private function __construct()
{
ErrorHandler::init();
$this->router = new Router();
}
/**
* Refuse cloning
*/
private function __clone(){}
/**
@ -46,23 +45,13 @@ class FrontController
*/
static public function getInstance()
{
if (! isset(self::$instance)) {
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* @param string $path
* @return FrontController
*/
public function setViewPath($path)
{
$this->view_path = $path;
return $this;
}
/**
* @param string $view
* @return FrontController
*/
@ -79,7 +68,7 @@ class FrontController
public function getView($view = null)
{
$view = ($view) ? $view : $this->view;
return new $view($this->view_path);
return new $view(Config::get($view));
}
/**
@ -106,29 +95,26 @@ class FrontController
public function execute()
{
try {
try {
$request = Env::getRequestUri();
$route = $this->getRouter()->route($request);
if (!$route) {
throw new Exception('Route "' . $request . '" not found');
}
$action_class = $route->getAction();
$action = new $action_class();
$layout_class = $route->getLayout();
$layout = new $layout_class();
return $layout->fetch($action);
} catch (GeneralException $e) {
throw $e;
} catch (Exception $e) {
throw new GeneralException($e->getMessage(), $e->getCode());
$request = Env::getRequestUri();
$route = $this->getRouter()->route($request);
if (!$route) {
throw new Error404Exception('Route "' . $request . '" not found');
}
} catch (Exception $e) {
$action_class = $route->getAction();
$action = new $action_class();
$layout_class = $route->getLayout();
$layout = new $layout_class();
return $layout->fetch($action);
} catch(Exception $e) {
if (DEBUG == true) {
return $e->toHtml();
return ErrorHandler::showDebug($e);
}
$layout = new DefaultLayout();
return $layout->fetch(new ErrorAction($e));
}
}
}