public static function run() { // run setup and prepare env static::setup(); // handle the requested uri $uri = static::parse(); $segments = array(); if (strlen($uri)) { $segments = explode('/', $uri); } // lets log our translated uri Log::info('Translated URI: ' . $uri); // set our action or our default if none is set $action = count($segments) ? array_shift($segments) : 'page'; // default to our front end router $controller = 'Routes'; // set the template path $theme = Config::get('metadata.theme'); Template::path(PATH . 'themes/' . $theme . '/'); // remove admin as an argument and set the default action if there isnt one if ($action == 'admin') { // set default controller for the admin $controller = (count($segments) ? array_shift($segments) : 'posts') . '_controller'; // set default action $action = count($segments) ? array_shift($segments) : 'index'; // public admin actions $public = array('users/login', 'users/amnesia', 'users/reset'); // redirect to login if (Users::authed() === false and in_array(trim($controller, '_controller') . '/' . $action, $public) === false) { return Response::redirect(Config::get('application.admin_folder') . '/users/login'); } // set template path for admin Template::path(PATH . 'system/admin/theme/'); } // log the controller we are going to use and the action Log::info('Controller action: ' . $controller . '/' . $action); // check we can find a action $reflector = new ReflectionClass($controller); if ($reflector->isInstantiable() === false or $reflector->hasMethod($action) === false) { // default back to front end template for 404 page Template::path(PATH . 'themes/' . $theme . '/'); // report error Log::warning($reflector->isInstantiable() === false ? 'Controller was not Instantiable' : 'Action does not exist'); // method not found in controller return Response::error(404); } $reflector->getMethod($action)->invokeArgs(new $controller(), $segments); }
function __construct() { self::$path = $_SESSION['URL_SYS']; }