From bdbde33a02088cb39645f2a3c7d7ba367a1e0d2c Mon Sep 17 00:00:00 2001 From: Benjamin Calef Date: Mon, 12 Jun 2023 13:06:37 +0200 Subject: [PATCH] [v2.0.1] add argument to set envFilePath --- MagentoDotenv.php | 29 +++++++++++++++++------------ composer.json | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/MagentoDotenv.php b/MagentoDotenv.php index 98deb3f..1dcd668 100644 --- a/MagentoDotenv.php +++ b/MagentoDotenv.php @@ -31,19 +31,18 @@ class MagentoDotenv */ public static function init(): void { - if (!file_exists(ROOT_DIRECTORY . self::MAGENTO_BOOTSTRAP_FILE)) { - return; - } - - $dotenvSrc = ROOT_DIRECTORY . self::SRC_APP_ETC_DOTENV_FILE; $dotenvDest = ROOT_DIRECTORY . self::DEST_APP_ETC_DOTENV_FILE; - if (!file_exists($dotenvDest)) { - copy($dotenvSrc, $dotenvDest); + if (\is_file($dotenvDest)) { + require_once $dotenvDest; + return; + } else { + $dotenvSrc = ROOT_DIRECTORY . self::SRC_APP_ETC_DOTENV_FILE; + \copy($dotenvSrc, $dotenvDest); } - $envFile = ROOT_DIRECTORY . self::ENV_FILE; - if (!file_exists($envFile)) { - touch($envFile); + $magentoBootstrapFile = ROOT_DIRECTORY . self::MAGENTO_BOOTSTRAP_FILE; + if (!\is_file($magentoBootstrapFile)) { + return; } require_once $dotenvDest; @@ -53,16 +52,22 @@ public static function init(): void * @param bool $usePutEnv * @param string $envKey * @param string $debugKey + * @param string $envFilePath * @return SymfonyDotenv */ public static function get( bool $usePutEnv = false, string $envKey = self::ENV_KEY, - string $debugKey = self::DEBUG_KEY + string $debugKey = self::DEBUG_KEY, + string $envFilePath = '' ): SymfonyDotenv { + if ($envFilePath !== '') { + $envFilePath = $envFilePath . DIRECTORY_SEPARATOR; + } + $dotenv = new SymfonyDotenv($envKey, $debugKey); $dotenv->usePutEnv($usePutEnv); - $dotenv->loadEnv(ROOT_DIRECTORY . self::ENV_FILE); + $dotenv->loadEnv(ROOT_DIRECTORY . $envFilePath . self::ENV_FILE); return $dotenv; } diff --git a/composer.json b/composer.json index 8a1a83d..7673aa5 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Simple autoloader to integrate the Symfony Dotenv component into Magento2", "keywords": ["magento2", "environment", "env", "dotenv"], "type": "magento2-component", - "version": "2.0.0", + "version": "2.0.1", "authors":[ { "name": "Benjamin Calef",