8
0
daux.io/libs/Generator/Helper.php

46 Zeilen
1.3 KiB
PHP

2015-04-22 12:23:57 +02:00
<?php namespace Todaymade\Daux\Generator;
2015-04-23 00:32:30 +02:00
class Helper
{
public static function copyAssets($path, $local_base)
{
2015-04-22 12:23:57 +02:00
@mkdir($path);
2015-04-23 00:32:30 +02:00
static::rmdir($path);
@mkdir($path . DS . 'resources');
static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources');
2015-04-22 12:23:57 +02:00
}
2015-04-23 00:32:30 +02:00
private static function rmdir($dir)
{
2015-04-22 12:23:57 +02:00
$it = new \RecursiveDirectoryIterator($dir);
$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
2015-04-23 00:32:30 +02:00
foreach ($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
2015-04-22 12:23:57 +02:00
}
}
2015-04-23 00:32:30 +02:00
private static function copyRecursive($src, $dst)
{
2015-04-22 12:23:57 +02:00
$dir = opendir($src);
@mkdir($dst);
2015-04-23 00:32:30 +02:00
while (false !== ( $file = readdir($dir))) {
2015-04-22 12:23:57 +02:00
if (( $file != '.' ) && ( $file != '..' )) {
2015-04-23 00:32:30 +02:00
if (is_dir($src . '/' . $file)) {
static::copyRecursive($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
2015-04-22 12:23:57 +02:00
}
}
}
closedir($dir);
}
}