public static function rmdir($dir)
{
+ if (PHP_OS_FAMILY !== 'Windows') {
+ `rm -rf $dir`;
+ if (!file_exists($dir)) {
+ return;
+ }
+ }
$files = self::getRecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
throw new \RuntimeException(sprintf('Directory "%s" was not created. %s', $path, $e->getMessage()));
}
}
- return realpath($path).'/';
+ return realpath($path) . '/';
}
- public static function emptyDir($path){
- if(file_exists($path)){
+ public static function emptyDir($path)
+ {
+ if (file_exists($path)) {
self::rmdir($path);
}
return self::mkdir($path);
}
/**
- * @param $source string
+ * @param $source string|array
* @param $zip string
+ * @param int $compression
* @return CommandLine
*/
- public static function archive($source, $zip)
+ public static function archive($source, $zip, $compression = 0)
{
$zipexe = 'zip';
+ if (!is_numeric($compression)) {
+ $compression = 0;
+ }
+ $compression = round($compression);
+ $compression = max(0, min(9, $compression));
+
$cl = new CommandLine($zipexe);
if (is_array($source)) {
+ $cl->setArg($compression);
$cl->setArg('j');
$cl->setArg(null, $zip);
foreach ($source as $item) {
}
} else if (@is_dir($source)) {
$cl->cd($source);
+ $cl->setArg($compression);
$cl->setArg('r');
$cl->setArg(null, $zip);
$cl->setArg(null, '*');