public static function setDirMod($directory, $mod = '0755') { if (!Hi_Tool_Dir::isDirectory($directory)) { return false; } return @chmod($directory, $mod); }
/** * 将zipFile抽取到路径$to,如果$to不存在将自动创建 * * @param unknown_type $zipFile * @param unknown_type $to */ public function extract($zipFile, $to) { Hi_Tool_Dir::check($to); $to = Hi_Tool_Dir::standard($to); $zip = new ZipArchive(); $res = $zip->open($zipFile); if ($res !== true) { return false; } $zip->extractTo($to); }
/** * 保存日誌內容到文件 * * @param $logFile * @param $content * @return bool */ public static function save($logFile, $content) { if (!Hi_Tool_Dir::isAbsolute($logFile)) { $logFile = Hi_Env::$PATH_LOG . DS . $logFile; } $dir = dirname($logFile); Hi_Tool_Dir::check($dir); if (!is_string($content)) { $content = var_export($content, true); } $content = date('Y-m-d H:i:s') . "\t" . $content . "\n"; $fp = fopen($logFile, 'a'); fwrite($fp, $content, strlen($content)); fclose($fp); return true; }
/** * 检查应用的部署路径是不是合法 * * @param string $path */ private function _checkPath($path) { if (!is_dir($path) || !is_readable($path)) { throw new Hi_Exception('应用路径必须是一个可读的路径'); } $path = Hi_Tool_Dir::standard($path); if (substr($path, -1) != DS) { $path .= DS; } if (!is_file($path . 'config.xml')) { throw new Hi_Exception('在应用的部署路径下没有找到配置文件 "config.xml"'); } if (!is_dir($path . 'class') || !is_readable($path . 'class')) { throw new Hi_Exception('没有找到class路径'); } $classPath = $path . 'class'; $ad = $classPath . DS . 'Action'; if (!is_dir($ad)) { throw new Hi_Exception('没有找到Action路径'); } }
/** * 设置缓存路径 * * @param string $cacheDir * @throws Hi_Cache_Exception */ public function setCacheDir($cacheDir) { if (Hi_Tool_Dir::is($cacheDir) && !Hi_Tool_Dir::writable($cacheDir)) { throw new Hi_Cache_Exception('Cache path must be a writable'); } if (substr($cacheDir, -1) != DIRECTORY_SEPARATOR) { $cacheDir = $cacheDir . DIRECTORY_SEPARATOR; } $this->_dir = $cacheDir; return true; }
public static function getUrlFile($url) { if (preg_match('/^http:\\/\\/.+?\\/([^\\?]+)/i', $url, $regs)) { $url = $regs[1]; } $file = DOC_ROOT . $url; $file = Hi_Tool_Dir::standard($file); return $file; }
protected function _setView() { if ($this->_view instanceof Hi_View) { return $this->_view; } $sc = $this->_config->smarty; if (empty($sc->template)) { $tplDir = Hi_Env::$PATH_APP . DS . 'templates'; } else { $tplDir = $sc->template; } if (!is_dir($tplDir)) { throw new Hi_Exception('没有找到模板位置'); } $this->_view = new Hi_View(); $this->_view->template_dir = $tplDir; if (empty($sc->template_c) || !is_dir($sc->template_c)) { $this->_view->compile_dir = Hi_Env::$PATH_TMP . 'tempalte_c'; Hi_Tool_Dir::create($this->_view->compile_dir); } else { $this->_view->template_c = $sc->template_c; } $this->_view->caching = (int) $sc->cache; $this->_view->debugging = $sc->debug == 'true' ? true : false; return $this->_view; }
/** * 取$action对应的模板文件相对路径 * * @param string $action */ protected function _tplRelativeFile($action) { $this->_setView(); Hi_Tool_Dir::create($this->_view->template_dir . DS . $this->_subTplDir); return $this->_subTplDir . DS . $this->_table->getName() . '.' . $action . '.html'; }