function execute() { if (!is_dir($this->_source_dir)) { throw new Command_Exception("Invalid source dir: \"{$this->_source_dir}\"."); } echo "processing source documents..."; $book = new Doc_Book(Helper_YAML::load("{$this->_source_dir}/toc.yaml"), $this->_source_dir); echo "ok\n"; $this->_output_dir = "{$this->_output_dir}/{$book->name}"; if (!is_dir($this->_output_dir)) { Helper_FileSys::mkdirs($this->_output_dir); } $this->_output_dir = trim(realpath($this->_output_dir), '/\\'); switch ($this->_docmode) { case 'online': $this->_buildOnlineDocuments($book); break; case 'chm': $this->_buildCHMDocuments($book); break; case 'pdf': $this->_buildPDFDocuments($book); break; case 'html': default: exit('invalid docmode:' . $this->_docmode); } }
protected function _copyAssets($source) { $sources = array($this->_source_dir . '/_assets', dirname(__FILE__) . '/../_assets', $source); foreach ($sources as $source_dir) { $dir = realpath($source_dir); if (empty($dir)) { continue; } Helper_FileSys::copyDir($dir, $this->_output_dir, array('level' => 1)); } }
/** * 建立需要的目录路径 * * @param string $dir */ protected function _createDirs($dir) { $dir = str_replace('/\\', DS, strtolower($dir)); if (!file_exists($dir)) { Helper_FileSys::mkdirs($dir, 0777); $dir = realpath($dir); $this->_log('Create directory "%s" successed.', $dir); } }
/** * 获得该模块所有模型的名字 * * @return array of model name */ function modelsName() { if (is_null($this->_models_name)) { $dir = rtrim($this->_module_dir, '/\\') . DS . 'model'; $files = Helper_FileSys::recursionGlob($dir, '*.php'); $this->_models_name = array(); foreach ($files as $file) { $info = QReflection_Model::testModelFile($file); if ($info == false) { continue; } $this->_models_name[$file] = $info['class']; } asort($this->_models_name, SORT_STRING); } return $this->_models_name; }
/** * 移动上传文件到指定位置和文件名 * * @param string $dest_path 目的地路径 * * @return Helper_Uploader_File 连贯接口 */ function move($dest_path) { $test = pathinfo($dest_path); if (!isset($test['extension'])) { $dest_path = $dest_path . '.' . $this->extname(); } if (!is_dir($path = $test['dirname'])) { Helper_FileSys::mkdirs($path); } if ($this->_file['is_moved']) { $ret = rename($this->filepath(), $dest_path); } else { $this->_file['is_moved'] = true; if (stripos(PHP_OS, 'WIN') !== false) { $src_path = iconv("UTF-8", "gbk//IGNORE", $this->filepath()); $dest_path = iconv("UTF-8", "gbk//IGNORE", $dest_path); $ret = move_uploaded_file($src_path, $dest_path); } else { $ret = move_uploaded_file($this->filepath(), $dest_path); } if (!$ret) { $ret = rename($this->filepath(), $dest_path); } } if ($ret) { //chown($dest_path,'www-data'); $this->_file['full_path'] = $dest_path; } return $this; }
/** * 返回应用程序在 config 目录中的所有配置文件的文件名 * * @return array */ function configFiles() { $dir = rtrim(realpath($this->_app_config['CONFIG_DIR']), '/\\'); $ext = $this->_app_config['CONFIG_FILE_EXTNAME']; $files = Helper_FileSys::recursionGlob($dir, "*.{$ext}"); $return = array(); $l = strlen(rtrim($dir, '/\\') . DS); foreach ($files as $path) { $return[] = substr(realpath($path), $l); } return $return; }
protected function _buildModel() { $options = array('extnames' => 'php', 'excludes' => $this->_excludes); $files = Helper_FileSys::findFiles($this->_source_dir, $options); return API_Model::create()->docsDir($this->_docs_dir)->build($files); }