]> _ Git - cubist_util.git/commitdiff
wip #5294 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 24 May 2022 11:29:43 +0000 (13:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 24 May 2022 11:29:43 +0000 (13:29 +0200)
src/Files/Files.php

index 92066dd2de6b401d22a8371998d8d2a33a2f2552..2ec990410ab3db39d4e79b1ed1304355d0d09d0a 100644 (file)
@@ -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