]> _ Git - cubist_util.git/commitdiff
wip #6260 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Sep 2023 09:37:05 +0000 (11:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Sep 2023 09:37:05 +0000 (11:37 +0200)
src/Env.php [new file with mode: 0644]
src/Files/Files.php

diff --git a/src/Env.php b/src/Env.php
new file mode 100644 (file)
index 0000000..5a919be
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace Cubist\Util;
+
+use Cubist\Util\Files\Files;
+
+class Env
+{
+    public static function mergeEnvFiles(...$files)
+    {
+        $f = '/tmp/.env.' . Files::hashFileAttributes($files);
+        if (!file_exists($f)) {
+            $res = '';
+            foreach ($files as $file) {
+                $res .= file_get_contents($file) . "\n\n";
+            }
+            file_put_contents($f, $res);
+        }
+        return $f;
+    }
+}
\ No newline at end of file
index 21f013659a748414e7cd46f7e172e3114628eb72..f88255045cee2dc5a7afd60e30c755d7b08d5259 100644 (file)
@@ -40,7 +40,7 @@ class Files
                     throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
                 }
             } catch (\Exception $e) {
-                if(!file_exists($path)) {
+                if (!file_exists($path)) {
                     throw new \RuntimeException(sprintf('Directory "%s" was not created. %s', $path, $e->getMessage()));
                 }
             }
@@ -145,12 +145,18 @@ class Files
         return $f->getBasename($suffix);
     }
 
-    public static function hashFileAttributes($path, $additionalAttributes = [])
+    public static function hashFileAttributes($paths, $additionalAttributes = [])
     {
-        $str = $path . '/$$' . filesize($path) . '///' . filemtime($path);
-        if ($additionalAttributes) {
-            $str .= '$$$' . print_r($additionalAttributes, true);
+        if (!is_array($paths)) {
+            $paths = [$paths];
         }
+        foreach ($paths as $path) {
+            $str = $path . '/$$' . filesize($path) . '///' . filemtime($path);
+            if ($additionalAttributes) {
+                $str .= '$$$' . print_r($additionalAttributes, true);
+            }
+        }
+
         return hash('sha256', $str);
     }