Esempio n. 1
0
 /**
  * Finds the route and gets the closure or controller
  * @return 	boolean 	doesn't answer anything, just to quit the method from running.
  * Errors that can be thrown here.
  * Code 		Desc
  * C_100		Controller file not found.
  * C_101		Controller classname not valid.
  * C_102		Methodname not valid. 
  */
 public function getPage()
 {
     $exp = explode('/', Url::uri());
     $i = count($exp);
     $_data = null;
     while ($i) {
         $s = implode('/', $exp);
         if (Url::uri() == '') {
             $s = '/';
         }
         $_data = Router::find($this->method, $s);
         if ($_data !== false) {
             break;
         }
         unset($exp[$i - 1]);
         $i--;
     }
     // Try to find a route that contains a wildcard.
     // Router::find_with_wildcard();
     $data = $_data;
     if ($data === false) {
         Error::register('http_404');
         return false;
     }
     if ($data['closure'] == true) {
         $this->view = $data['func']();
         if (!$this->view instanceof View) {
             $this->isView = false;
         }
     } else {
         // Getting the correct controller and method starts here.
         if (strpos($data['func'], '@') === false) {
             $this->content = $data['func'];
             return true;
         }
         list($controller, $method) = explode('@', $data['func']);
         if (!is_file(APP . 'controller/' . $controller . '.php')) {
             return Error::register('controller_100');
         }
         require_once APP . 'controller/' . $controller . '.php';
         $controller_name = $controller . '_Controller';
         if (!class_exists($controller_name)) {
             return Error::register('controller_101');
         }
         $ct = new $controller_name();
         $restful = isset($ct->restful) ? $ct->restful : false;
         $r_method = $restful === true ? $this->method . '_' : '';
         $method_name = $r_method . $method;
         if (!method_exists($controller_name, $method_name)) {
             return Error::register('controller_102');
         }
         $this->view = call_user_func(array($ct, $method_name));
         if (!$this->view instanceof View) {
             $this->isView = false;
         }
         if ($this->view instanceof Json) {
             $this->isJson = true;
         }
     }
 }
Esempio n. 2
0
 public static function boot()
 {
     Config::init();
     require_once SYS . 'model/database/connector.php';
     require_once COMPONENTS . 'database/nitrogen/nitrogen.php';
     require_once COMPONENTS . 'database/nitrogen/builder.php';
     require_once SYS . 'model/model.php';
     Autoload::load();
     Request::init();
     Response::init();
     Url::init();
     Log::init();
     $boot = new Bootstrap(Config::$path);
     $boot->getPage();
     $boot->getContent();
     if (Config::$profiler === true) {
         echo Log::render();
     }
 }