From: Vincent Vanwaelscappel Date: Tue, 24 May 2022 11:29:43 +0000 (+0200) Subject: wip #5294 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5d26e60b3eb84408bf95757dfb60b266f69af5f9;p=cubist_util.git wip #5294 @3 --- diff --git a/src/Files/Files.php b/src/Files/Files.php index 92066dd..2ec9904 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -130,8 +130,9 @@ class Files return $f->getBasename($suffix); } - public static function hashFileAttributes($path){ - return hash('sha256',$path.'/$$'.filesize($path).'///'.filemtime($path)); + public static function hashFileAttributes($path) + { + return hash('sha256', $path . '/$$' . filesize($path) . '///' . filemtime($path)); } public static function copyFile($from, $to, $hashAlgo = false) @@ -280,14 +281,31 @@ class Files * @param ...$files string * @return string|null */ - public static function firstThatExists(...$files){ + public static function firstThatExists(...$files) + { foreach ($files as $file) { - if(file_exists($file)){ + if (file_exists($file)) { return $file; } } return null; } + public static function recursiveReplaceStringInDir($path, $replace = []) + { + $files=self::getRecursiveDirectoryIterator($path); + foreach ($files as $file) { + /** @var $file \SplFileInfo */ + if($file->isDir()){ + continue; + } + $c=file_get_contents($file->getPathname()); + foreach ($replace as $k=>$v) { + $c=str_replace($k,$v,$c); + } + file_put_contents($file->getPathname(),$c); + } + } + } \ No newline at end of file