Example #1
0
 public function query($query, $op = 'r')
 {
     $this->resource = false;
     mgTrace();
     $this->resource = mysql_query($query) or $this->databaseException($query);
     mgTrace(false);
     mgDebug('Excute SQL', $query);
     return $this->resource;
 }
Example #2
0
 public function runAction()
 {
     require $this->fileName;
     $o = $this->objName;
     mgTrace();
     $tmp = new $o();
     mgTrace(false);
     mgDebug('Create Module', $tmp);
     mgTrace();
     $output = $tmp->runModule($this->args);
     mgTrace(false);
     mgDebug('Run Module', $tmp);
     $this->stack['action']['content_type'] = "content-Type: {$this->stack['static_var']['content_type']}; charset={$this->stack['static_var']['charset']}";
     header($this->stack['action']['content_type']);
     echo $output;
 }
Example #3
0
 private function runKernelModule()
 {
     $requireObjects = array();
     require __DIR__ . '/action/require_objects.php';
     foreach ($requireObjects as $file => $object) {
         require_once __DIR__ . '/kernel/' . $file;
         //创建核心模块
         mgTrace();
         $tmp = new $object();
         mgTrace(false);
         mgDebug('Create Kernel Module', $tmp);
         //运行入口函数
         $moduleName = mgClassNameToFileName($object);
         mgTrace();
         $this->stack[$moduleName] = $tmp->runModule();
         mgTrace(false);
         mgDebug('Run Kernel Module', $tmp);
     }
 }
Example #4
0
 protected function loadModel($model, $triggerException = true)
 {
     if (isset($this->globalModel[$model])) {
         return $this->globalModel[$model];
     } else {
         mgTrace();
         $modelFile = __MODEL__ . '/model.' . $model . '.php';
         $object = mgFileNameToClassName($model);
         if (!class_exists($object . 'Model')) {
             if (file_exists($modelFile)) {
                 require_once $modelFile;
                 if (isset($this->stack['action']['application_cache_path'])) {
                     file_put_contents($this->stack['action']['application_cache_path'], __DEBUG__ ? file_get_contents($this->stack['action']['application_cache_path']) . mgGetScript(file_get_contents($modelFile)) : file_get_contents($this->stack['action']['application_cache_path']) . mgGetScript(php_strip_whitespace($modelFile)));
                 }
                 if (isset($this->stack['action']['application_config_path'])) {
                     $files = array();
                     require $this->stack['action']['application_config_path'];
                     $files[$modelFile] = filemtime($modelFile);
                     mgExportArrayToFile($this->stack['action']['application_config_path'], $files, 'files');
                 }
             } else {
                 if ($triggerException) {
                     $this->throwException(E_MODELFILENOTEXISTS, $modelFile);
                 } else {
                     return NULL;
                 }
             }
         }
         $object = $object . 'Model';
         $tmp = new $object();
         $this->globalModel[$model] = $tmp;
         mgTrace(false);
         mgDebug('Load Model', $tmp);
         return $tmp;
     }
 }
Example #5
0
 public function runAction()
 {
     $module = array();
     //初始化module数组
     $args = array();
     //初始化args数组
     $hasRun = array();
     //已经运行的模块
     $waitting = array();
     //正在等待的模块
     $this->stack['action']['application_cache_path'] = __RUNTIME__ . '/template/' . mgPathToFileName($this->compileFile) . '.mod.php';
     $this->stack['action']['application_config_path'] = __RUNTIME__ . '/template/' . mgPathToFileName($this->compileFile) . '.cnf.php';
     require $this->stack['action']['application_cache_path'];
     foreach ($module as $nameSpace => $object) {
         //创建module
         mgTrace();
         $tmp = new $object();
         mgTrace(false);
         mgDebug('Create Module', $tmp);
         if ($tmp->waittingFor && isset($module[$tmp->waittingFor]) && !isset($hasRun[$tmp->waittingFor])) {
             $waitting[$nameSpace] = $tmp;
             continue;
         }
         //运行模块入口函数runModule并将运行结果保存到临时堆栈中
         mgTrace();
         $stack = $tmp->runModule(isset($args[$nameSpace]) ? $args[$nameSpace] : array());
         mgTrace(false);
         mgDebug('Run Module', $tmp);
         //将临时堆栈中的数据转移到全局堆栈中
         $this->stack = $this->pushData(explode('.', $nameSpace), $stack, $this->stack);
         $hasRun[$nameSpace] = $object;
     }
     foreach ($waitting as $key => $object) {
         //运行模块入口函数runModule并将运行结果保存到临时堆栈中
         mgTrace();
         $stack = $object->runModule(isset($args[$key]) ? $args[$key] : array());
         mgTrace(false);
         mgDebug('Run Module', $tmp);
         //将临时堆栈中的数据转移到全局堆栈中
         $this->stack = $this->pushData(explode('.', $key), $stack, $this->stack);
     }
     $this->stack['action']['prase_time'] = substr(mgGetMicrotime() - $this->stack['action']['prase_time'], 0, 6);
     $this->stack['action']['content_type'] = "content-Type: {$this->stack['static_var']['content_type']}; charset={$this->stack['static_var']['charset']}";
     //定义头文件
     header($this->stack['action']['content_type']);
     $data = $this->stack;
     require __COMPILE__ . '/' . mgPathToFileName($this->compileFile) . '.php';
 }