/** * 写日志 * * @param type $message */ public static function log($message, $type = 'error') { $now = time(); $time = date('Y-m-d H:i:s', $now); $file_name = "{$type}_" . date('Ymd', $now); $message = "\n{$time}: {$message}"; if (self::$file_path) { if (!is_dir(self::$file_path)) { mkdir(self::$file_path, 0775, true); } $file_path = Star_Loader::getFilePath(array(self::$file_path, $file_name), '.txt'); } else { $directory = Star_Loader::getModuleDirect(self::$directory_name); if (!is_dir($directory)) { mkdir($directory, 0775, true); } $file_path = Star_Loader::getFilePath(array($directory, $file_name), '.txt'); } $handle = fopen($file_path, self::$model, false); fwrite($handle, $message); fclose($handle); }
/** * 加载controller * * @param string $controller * @throws Star_Exception */ public function loadClass($controller) { $file_path = Star_Loader::getFilePath(array($this->getControllerDirectory(), $controller)); if (Star_Loader::isExist($file_path) == false) { throw new Star_Exception("{$file_path} not found!", 404); } //文件是否可读 if (!Star_Loader::isReadable($file_path)) { throw new Star_Exception("Connot load controller calss {$controller} from file {$file_path}", 500); } require $file_path; //类是否存在 if (!class_exists($controller, false)) { throw new Star_Exception("Invalid controller class ({$controller})", 404); } }
/** * 获取模板绝对地址 * * @param $file_name * @return type */ private function getTemplatePath($file_name) { $view_segments = array($this->_base_name, $this->_template_name, $file_name); $view_path = Star_Loader::getFilePath($view_segments, $this->_postfix); return $view_path; }