Created
July 7, 2011 06:03
-
-
Save koriym/1068967 to your computer and use it in GitHub Desktop.
Put require scirpt each dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// en: Put require scirpt each dir in case of you can't rely default include_path. (Script use relative path.) | |
// ja: デフォルトのincludeパスが使用できない場合に各ディレクトリにrequireのみを相対パスで行うファイルを配置します。 | |
// | |
// config | |
$initFileName = 'App.php'; | |
$initFilePath = '../../'; | |
// /config | |
// main | |
$list = arrayDirList(); | |
$file = __DIR__ . DIRECTORY_SEPARATOR . $initFileName; | |
foreach ($list as $dir) { | |
$fullPath = $dir . '/' . $initFileName; | |
$info = pathinfo($fullPath); | |
$path = str_replace(__DIR__, '', $info['dirname']); | |
$depth = substr_count($path, '/'); | |
$relativePath = str_repeat('../', $depth); | |
$contents = "<?php require_once '{$relativePath}{$initFileName}';"; | |
file_put_contents($fullPath, $contents); | |
echo "[ADD] $fullPath\n"; | |
} | |
/** | |
* Return dir list | |
* | |
* @param string $path | |
* @param string $path | |
* @return array | |
* @see http://q.hatena.ne.jp/1201401875 | |
*/ | |
function arrayDirList($path = __DIR__, $level=30) { | |
$dirlist = array(); | |
static $dirFullPathList = array(); | |
if ($level) { | |
$dh = opendir($path); | |
while (($filename = readdir($dh))) { | |
if ($filename[0] == '.' || $filename == '.' || $filename == '..') | |
continue; | |
else { | |
$realpath = $path.'/'.$filename; | |
if (is_link($realpath)) { | |
continue; | |
}else if (is_file($realpath)) { | |
//$dirlist[] = $filename; | |
} else if (is_dir($realpath)) { | |
$dirlist[$filename] = arrayDirList($realpath, $level-1); | |
$dirFullPathList[] = realpath($realpath); | |
} | |
} | |
} | |
closedir($dh); | |
} | |
return $dirFullPathList; | |
//return $dirlist; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment