示例#1
0
 public function dispatch()
 {
     $model_info = $this->router()->parse_url();
     if (empty($model_info)) {
         //$this->_response->res('404');
         echo '404 The page is not exist!';
         exit;
         //@todo 由<接收响应机制>
     }
     $app = $model_info['app'];
     $module = $model_info['module'];
     $action = $model_info['action'] ? $model_info['action'] : ($model_info['parameter']['action'] ? $model_info['parameter']['action'] : '');
     $default = $model_info['default'];
     $parameter = $model_info['parameter'];
     $this->_request->set_param($parameter, $default);
     $controller = ucfirst($module) . ucfirst($app) . 'Con';
     //call function and write response in the class reponse
     if (!method_exists(Blood::single($controller), $action)) {
         echo '404 The page is not exist!';
         exit;
     } else {
         Blood::single($controller)->{$action}();
     }
     //$this->_response->sendhttphead();
     $response = $this->_response->get_body();
     echo $response;
 }
示例#2
0
 public static function setup()
 {
     $sql_file_count = 0;
     $sql_command_count = 0;
     $install_lock = ROOT_DIR . '/config/slock.php';
     try {
         if (is_file($install_lock)) {
             return true;
         } else {
             $files_path = array();
             $all_files_flag = false;
             if (!defined('DB_FILES_DIR')) {
                 return new Exception('please setup your dir of files for DB!');
             }
             self::readdir(DB_FILES_DIR, $files_path);
             do {
                 $all_files_flag = true;
                 foreach ($files_path as $k => &$row) {
                     if ($row[1] == 'dir') {
                         $all_files_flag = false;
                         self::readdir($row[0], $files_path);
                         unset($files_path[$k]);
                     }
                 }
             } while ($all_files_flag == false);
             $sql_file_count = count($files_path);
             $sql_command_count = self::command_count($files_path);
             $command_per = 500.0 / $sql_command_count;
             if (ob_get_level() == 0) {
                 ob_start();
             }
             echo "<p>Installed the DB,count of files:{$sql_file_count},", "count of commands:{$sql_command_count}, please waiting......</p>", '<p id="loading_size"></p>', '<p style="width:500px;height:20px;background:#000000;">', '<span id="loading_img" style="float:left;height:20px;background:blue;text-align:center;"></span></p>';
             if (is_array($files_path) && !empty($files_path)) {
                 $setup_count = 0;
                 $db = Blood::DB(1);
                 foreach ($files_path as $file) {
                     $sql_arr = self::getline($file[0]);
                     if (is_array($sql_arr) && !empty($sql_arr)) {
                         foreach ($sql_arr as $v) {
                             if (preg_match('/^(\\s)*$/i', $v)) {
                                 continue;
                             }
                             $sql = $v . ';';
                             $res = $db->exec($sql);
                             if (!$res) {
                                 throw new Exception("The sql file has wrong syntax,check your file:{$file[0]}");
                             }
                             $setup_count++;
                             $comman_cur_per = $command_per * $setup_count;
                             echo "<script>document.getElementById('loading_img').style.width='", $comman_cur_per, "';document.getElementById('loading_size').innerText='" . round($comman_cur_per * 100 / 500) . "%';</script>";
                             ini_set('output_buffering', 0);
                             echo str_pad('', 4096) . "\n";
                             ob_flush();
                             flush();
                             sleep(1);
                         }
                     }
                 }
                 //create lock
                 if ($setup_count == $sql_command_count) {
                     echo '<button onclick="window.location.reload()">plese refresh the page</button>';
                     self::cfile($install_lock);
                 }
                 exit;
             }
         }
         //$ else
     } catch (Exception $e) {
         Blood::user_exception_handle();
         echo 'Message: ' . $e->getMessage();
     }
 }
示例#3
0
 public static function DB($ori = false)
 {
     try {
         if (!isset(self::$_db_obj)) {
             self::$_db_obj = new ModelLib($ori);
         }
         if (self::$_db_obj instanceof ModelInterfaceLib) {
             return self::$_db_obj;
         } else {
             throw new Exception('It has no db connection!');
         }
     } catch (Exception $e) {
         //self::user_exception_handle();
         echo 'Message: ' . $e->getMessage();
     }
 }
示例#4
0
 public function model($model_name = '')
 {
     if (class_exists($model_name)) {
         return Blood::single($model_name);
     } else {
         $ex_res = NutrientLib::class_explode(get_class($this));
         array_pop($ex_res);
         return Blood::single(implode('', $ex_res) . 'Mod');
     }
 }