Ejemplo n.º 1
0
$minDir = get_include_path().DIRECTORY_SEPARATOR.Asset::minDir();
assert('is_dir($jsSrc)');
assert('is_dir($cssSrc)');
assert('is_dir($minDir)');

// generate new ids
$ids = array();
if(!$handle = opendir($jsSrc)) trigger_error("couldn't open $jsSrc", E_USER_ERROR);
while(false !== ($jsfile = readdir($handle))) {
	if($jsfile == "." || $jsfile == "..") continue;
	$ids[] = DIRECTORY_SEPARATOR.JS::srcDir().DIRECTORY_SEPARATOR.$jsfile;
}
if(!$handle = opendir($cssSrc)) trigger_error("couldn't open $cssSrc", E_USER_ERROR);
while(false !== ($cssfile = readdir($handle))) {
	if($cssfile == "." || $cssfile == "..") continue;
	$ids[] = DIRECTORY_SEPARATOR.CSS::srcDir().DIRECTORY_SEPARATOR.$cssfile;
}

// delete contents of AssetManager::mindir()
if(!$handle = opendir($minDir)) trigger_error("couldn't open $minDir", E_USER_ERROR);
while(false !== ($entry = readdir($handle))) {
	if($entry == "." || $entry == "..") continue;
	$path = $minDir.DIRECTORY_SEPARATOR.$entry;
	echo "removing $path\n";
	if(!unlink($path)) trigger_error("couldn't unlink $path", E_USER_ERROR);
}

// for each file in ids, make an asset, generate minifile
foreach($ids as $key => $src) {
	$path = get_include_path().$src;
	$minifile = $minDir.DIRECTORY_SEPARATOR.base_convert($key, 10, 36).".".base_convert(filesize($path), 10, 36);