diff --git a/Load.php b/Load.php index c82b6c3..432cd2c 100644 --- a/Load.php +++ b/Load.php @@ -53,7 +53,7 @@ class Load trigger_error('Can\'t create directory: "' . $dir . '"', E_USER_ERROR); } - $scan = array(PATH . '/lib', PATH . '/' . APP . '/src'); + $scan = array(PATH . '/' . APP . '/src', PATH . '/lib'); require_once(PATH . '/lib/core/util/AutoloadBuilder.php'); diff --git a/app/Action.php b/app/Action.php index 1e734d9..457f9bf 100644 --- a/app/Action.php +++ b/app/Action.php @@ -20,12 +20,9 @@ abstract class Action protected function extractParams() { - $params = FrontController::getInstance()->getRouter()->getRoute()->getParams(); - if ($params) { - foreach ($params as $name => $value) { - if (is_string($name)) { - $this->$name = $value; - } + foreach (Env::getParam() as $name => $value) { + if (is_string($name)) { + $this->$name = $value; } } } diff --git a/app/ErrorAction.php b/app/ErrorAction.php index 0ffc9ee..d6370b0 100644 --- a/app/ErrorAction.php +++ b/app/ErrorAction.php @@ -20,8 +20,7 @@ class ErrorAction extends ViewAction public function __construct($exception) { $this->exception = $exception; - $this->view = FrontController::getInstance()->getView(); - $this->execute(); + parent::__construct(); } protected function execute() diff --git a/app/FrontController.php b/app/FrontController.php index 67d683e..2ea3154 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -100,12 +100,18 @@ class FrontController $request = Env::getRequestUri(); $route = $this->getRouter()->route($request); if (!$route) { - throw new Error404Exception('Route "' . $request . '" not found'); + throw new Error404Exception('Route for "' . $request . '" not found'); } $action_class = $route->getAction(); + if (!class_exists($action_class)) { + throw new GeneralException('Action class "' . $action_class . '" not found.'); + } $action = new $action_class(); $layout_class = $route->getLayout(); + if (!class_exists($layout_class)) { + throw new GeneralException('Layout class "' . $layout_class . '" not found.'); + } $layout = new $layout_class(); return $layout->fetch($action); @@ -113,7 +119,7 @@ class FrontController if (DEBUG == true) { return ErrorHandler::showDebug($e); } - $layout = new DefaultLayout(); + $layout = new ErrorLayout(); return $layout->fetch(new ErrorAction($e)); } } diff --git a/app/router/Router.php b/app/router/Router.php index 44ce240..4ad8915 100644 --- a/app/router/Router.php +++ b/app/router/Router.php @@ -25,7 +25,7 @@ class Router public function add($name, $route, $action, $params = null, $layout = null) { - if (! $layout) { + if (!$layout) { $layout = $this->default_layout; } $this->routes[$name] = new Route($route, $action, $params, $layout); @@ -37,8 +37,9 @@ class Router foreach ($this->routes as $name => $route) { if ($route->match($req)) { - $this->route_name = $route; + $this->route_name = $name; $this->route = $route; + Env::setParams($route->getParams()); return $this->route; } } diff --git a/classes/Env.class.php b/classes/Env.class.php index eafb9fe..bca691d 100644 --- a/classes/Env.class.php +++ b/classes/Env.class.php @@ -16,6 +16,8 @@ class Env static protected $request = null; + static protected $params = array(); + static public function getRequestUri() { if (self::$request === null) { @@ -100,4 +102,23 @@ class Env $res = isset($_FILES[$name]) ? $_FILES[$name] : $default; return $param ? $res[$param] : $res; } + + static public function getParam($key = null, $default = false) + { + if ($key === null) { + return self::$params; + } + return (isset(self::$params[$key])) ? self::$params[$key] : $default; + } + + static public function setParam($key, $value) + { + self::$params[$key] = $value; + } + + static public function setParams($params = array()) + { + self::$params = self::$params + $params; + } + } \ No newline at end of file diff --git a/exception/ErrorHandler.php b/exception/ErrorHandler.php index 18dd2f6..1bd7fc7 100644 --- a/exception/ErrorHandler.php +++ b/exception/ErrorHandler.php @@ -19,6 +19,7 @@ class ErrorHandler static public function error_handler($errno, $errstr, $errfile, $errline ) { + ob_clean(); throw new ErrorException($errstr, 0, $errno, $errfile, $errline); return false; } @@ -31,9 +32,9 @@ class ErrorHandler $i++; if($i >= $hiline - 10 && $i <= $hiline + 10) { if ($i == $hiline) { - $code[] = '
Variable | Value |
---|---|
' . $key . ' | ' . $value . ' |
{$exception->getMessage()}
Request Method: | {$method} |
---|---|
Exception Type: | {$class} |
Exception Message: | {$exception->getMessage()} |