]> _ Git - cubist_util.git/commitdiff
wip #5844 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Apr 2023 16:38:41 +0000 (18:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Apr 2023 16:38:41 +0000 (18:38 +0200)
src/Files/Files.php
src/Files/VirtualDirectory.php

index 5b487d43bba1a4bf48d91c2fa109b1209402225c..dd93bee4bd6b0579ca26c03814011b3216f5b4a2 100644 (file)
@@ -390,4 +390,23 @@ class Files
         return $res;
     }
 
+    /**
+     * @param $search string
+     * @param $replace string
+     * @param $filenames string|string[]
+     * @return void
+     */
+    public static function str_replace($search, $replace, $filenames)
+    {
+        if (!is_array($filenames)) {
+            $filenames = [$filenames];
+        }
+        foreach ($filenames as $filename) {
+            if (!file_exists($filename)) {
+                continue;
+            }
+            file_put_contents($filename, str_replace($search, $replace, file_get_contents($filename)));
+        }
+    }
+
 }
\ No newline at end of file
index 3a40b64fc693e6a5d1e422f972db6dae220ce00f..e3d5c0aabe0fcebcc9e902b89872da65be956076 100644 (file)
@@ -33,6 +33,9 @@ class VirtualDirectory
             return $this;
         }
         if ($prepend) {
+            if (isset($this->_copy[$realto])) {
+                return $this;
+            }
             $this->_copy = array_merge([$realto => $from], $this->_copy);
         } else {
             $this->_copy[$realto] = $from;
@@ -84,7 +87,7 @@ class VirtualDirectory
                 throw new \Exception(sprintf('Failed to copy %s to %s. Source doesn\'t exist', $from, $to));
             }
 
-            if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) > filemtime($to)) {
+            if (!file_exists($to) || filesize($from) !== filesize($to) || filemtime($from) !== filemtime($to)) {
                 try {
                     `cp -p $from $to`;
                 } catch (\Exception $e) {