--- /dev/null
+<?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
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()));
}
}
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);
}