do not edit the file, just return the file with the var set
authorEduardo <[email protected]>
Sat, 11 Nov 2023 16:11:50 +0000 (17:11 +0100)
committerEduardo <[email protected]>
Sat, 11 Nov 2023 16:11:50 +0000 (17:11 +0100)
page-generator/generator.php

index abaf48328359f263120c74d20318260bafb3ee7f..928fa509f1ff3b2290957e9ab84205208b6af3ff 100644 (file)
@@ -77,15 +77,16 @@ class CodeGenerator
     }
 
     /**
-     * Replace a template variable with a given value
+     * Replace a template variable with a given value and return the new content string
      */
     function setTemplateVar(string $filePath, string $var, string $value)
     {
         $replaceVar = "$$" . $var . "$$";
 
-        $content = file_get_contents($filePath);
-        $content = str_replace($replaceVar, $value, $content);
-        file_put_contents($filePath, $content, LOCK_EX);
+        if (file_exists($filePath))
+            return str_replace($replaceVar, $value, file_get_contents($filePath));
+        else
+            return str_replace($replaceVar, $value, $filePath);
     }
 
     /**