From 5d26e60b3eb84408bf95757dfb60b266f69af5f9 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 24 May 2022 13:29:43 +0200 Subject: [PATCH] wip #5294 @3 --- src/Files/Files.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) 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 -- 2.39.5