Example #1
0
 /**
  * ディレクトリごと再帰的に削除
  *
  * 中にファイルが入っていても削除する。
  *
  * @param string $dir ディレクトリ名
  * @param bool $remove_top トップのディレクトリを削除するか
  * @param string $hook_func 削除ごとに実行する関数を指定。
  */
 public static function removeDir($dir, $remove_top = true, $hook_func = '')
 {
     if (is_file($dir)) {
         unlink($dir);
         if ($hook_func) {
             call_user_func($hook_func, 'delete_file', $dir);
         }
     } else {
         if (is_dir($dir)) {
             if (ECF_FILE_FILESYSTEMITERATOR_EXIST) {
                 $iterator = new RecursiveDirectoryiterator($dir, FilesystemIterator::SKIP_DOTS);
             } else {
                 $iterator = new RecursiveDirectoryiterator($dir);
             }
             foreach ($iterator as $path) {
                 if ($path->isDir()) {
                     File::removeDir($path->getPathname());
                 } else {
                     unlink($path->getPathname());
                 }
             }
             if ($remove_top) {
                 rmdir($dir);
                 if ($hook_func) {
                     call_user_func($hook_func, 'delete_dir', $dir);
                 }
             }
         }
     }
     if (file_exists($dir)) {
         return false;
     } else {
         return true;
     }
 }
Example #2
0
function plugin_button_publish(array $params, Phest $phest)
{
    $phest->registerSection('publish', 'Publish');
    $phest->registerSection('publisherror', 'Publishエラー', array('type' => 'danger'));
    $dir_docs = DIR_PHEST . '/../docs';
    if (!is_dir($dir_docs)) {
        $phest->add('publisherror', 'docs ディレクトリが見つかりません');
        return false;
    }
    File::removeDir($dir_docs);
    mkdir($dir_docs, 0777);
    $phest->add('publish', 'docs/フォルダをクリアしました');
    $dir_production = $phest->getOutputPath('', 'production');
    if (!is_dir($dir_production)) {
        $phest->add('publisherror', 'output/production ディレクトリが見つかりません');
        return false;
    }
    File::copyDir($dir_production, $dir_docs);
    $phest->add('publish', 'docs/フォルダへoutput/productionの内容をコピーしました');
    $path_readme = $dir_docs . '/README.md';
    if (!file_exists($path_readme)) {
        $phest->add('publisherror', 'README.mdが見つかりません');
        echo $path_readme;
        return false;
    }
    rename($dir_docs . '/README.md', DIR_PHEST . '/../README.md');
    $phest->add('publish', 'docs/README.mdをトップへ移動しました');
    rename($dir_docs . '/CHANGELOGS.md', DIR_PHEST . '/../CHANGELOGS.md');
    $phest->add('publish', 'docs/CHANGELOGS.mdをトップへ移動しました');
}
Example #3
0
/**
 * フォルダを削除する
 *
 * @param  array  $params パラメータ
 * @param  string  $params.dir 削除対象のフォルダパス (source/ からの相対パス)
 * @param  Phest   $phest Phestオブジェクト
 * @return bool プラグインの成功判定
 */
function plugin_build_removedir(array $params, Phest $phest)
{
    if (empty($params['dir'])) {
        $phest->add('builderror', '[removedir] dirオプションが指定されていません');
        return false;
    }
    $dir_source = $phest->getSourcePath();
    $dpath = $dir_source . '/' . $params['dir'];
    if (!is_dir($dpath)) {
        $phest->add('builderror', '[removedir] dir はディレクトリではありません: ' . $dpath);
        return false;
    }
    $phest->add('build', '[removedir] <b>' . $dpath . '</b> を削除しました');
    File::removeDir($dpath);
    return true;
}
Example #4
0
         $inc_yaml = array();
     }
     $core_vars_yaml = array_merge_recursive_distinct($core_vars_yaml, $inc_yaml);
 }
 //------------- build処理
 $lang_list = $config_yaml['languages'];
 if ($lang_list) {
     if (!file_exists($path_languages_yml)) {
         File::buildTouch($path_languages_yml);
     }
     $LG = new LanguageBuilder($phest, $lang_list);
     $LG->process($path_languages_yml);
 }
 $build_option = '';
 if (!empty($config_yaml['buildclear'])) {
     File::removeDir($dir_output);
     mkdir($dir_output, 0777);
 }
 if ($build_option) {
     $build_option = ' <code>' . trim($build_option) . '</code>';
 }
 $phest->add('build', 'ビルド元: ' . realpath($dir_source));
 $phest->add('build', 'ビルド先: <a href="' . $home_local . '" target="_blank">' . realpath($dir_output) . '</a>' . $build_option);
 if (class_exists('FilesystemIterator', false)) {
     $ite = new RecursiveDirectoryIterator($dir_content, FilesystemIterator::SKIP_DOTS);
 } else {
     $ite = new RecursiveDirectoryIterator($dir_content);
 }
 $urls = array();
 $assets_list = array();
 $assets_smarty_flag = array();