2015-04-22 12:23:57 +02:00
|
|
|
<?php namespace Todaymade\Daux\Generator;
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
class Helper
|
|
|
|
{
|
2015-07-17 23:38:06 +02:00
|
|
|
/**
|
|
|
|
* Copy all files from $path to $local_base
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param string $local_base
|
|
|
|
*/
|
2015-04-23 00:32:30 +02:00
|
|
|
public static function copyAssets($path, $local_base)
|
|
|
|
{
|
2015-07-17 23:38:06 +02:00
|
|
|
mkdir($path);
|
2015-04-23 00:32:30 +02:00
|
|
|
static::rmdir($path);
|
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
mkdir($path . DS . 'resources');
|
2015-04-23 00:32:30 +02:00
|
|
|
static::copyRecursive($local_base . DS . 'resources', $path . DS . 'resources');
|
2015-04-22 12:23:57 +02:00
|
|
|
}
|
|
|
|
|
2015-07-17 23:38:06 +02:00
|
|
|
/**
|
|
|
|
* Remove a directory recursively
|
|
|
|
*
|
|
|
|
* @param string $dir
|
|
|
|
*/
|
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-07-17 23:38:06 +02:00
|
|
|
/**
|
|
|
|
* Copy files recursively
|
|
|
|
*
|
|
|
|
* @param string $source
|
|
|
|
* @param string $destination
|
|
|
|
*/
|
|
|
|
private static function copyRecursive($source, $destination)
|
2015-04-23 00:32:30 +02:00
|
|
|
{
|
2015-07-17 23:38:06 +02:00
|
|
|
$dir = opendir($source);
|
|
|
|
mkdir($destination);
|
|
|
|
while (false !== ($file = readdir($dir))) {
|
|
|
|
if ($file != '.' && $file != '..') {
|
|
|
|
if (is_dir($source . '/' . $file)) {
|
|
|
|
static::copyRecursive($source . '/' . $file, $destination . '/' . $file);
|
2015-04-23 00:32:30 +02:00
|
|
|
} else {
|
2015-07-17 23:38:06 +02:00
|
|
|
copy($source . '/' . $file, $destination . '/' . $file);
|
2015-04-22 12:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
}
|
|
|
|
}
|