return hash('sha256', $path . '/$$' . filesize($path) . '///' . filemtime($path));
}
- public static function copyFile($from, $to, $hashAlgo = false)
+ public static function copyFile($from, $to, $hashAlgo = false, $touch = true)
{
$do = true;
$frommtime = filemtime($from);
if (file_exists($to) && $frommtime === filemtime($to) && filesize($from) === filesize($to)) {
if ($hashAlgo) {
- $do = hash_file($hashAlgo, $from) !== hash_file($hashAlgo, $from);
+ $do = hash_file($hashAlgo, $from) !== hash_file($hashAlgo, $to);
} else {
$do = false;
}
}
+
if (!$do) {
return false;
}
+
copy($from, $to);
- touch($to, $frommtime);
+
+ if ($touch) {
+ touch($to, $frommtime);
+ }
+
return true;
}
public static function copy($from, $to, $context = null)
{
-
if (!file_exists($to)) {
mkdir($to, 0777, true);
}
public static function recursiveReplaceStringInDir($path, $replace = [])
{
- $files=self::getRecursiveDirectoryIterator($path);
+ $files = self::getRecursiveDirectoryIterator($path);
foreach ($files as $file) {
/** @var $file \SplFileInfo */
- if($file->isDir()){
+ if ($file->isDir()) {
continue;
}
- $c=file_get_contents($file->getPathname());
- foreach ($replace as $k=>$v) {
- $c=str_replace($k,$v,$c);
+ $c = file_get_contents($file->getPathname());
+ foreach ($replace as $k => $v) {
+ $c = str_replace($k, $v, $c);
}
- file_put_contents($file->getPathname(),$c);
+ file_put_contents($file->getPathname(), $c);
}
}