Skip to content

Commit

Permalink
[v2.0.1] add argument to set envFilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Calef committed Jun 12, 2023
1 parent a663d48 commit bdbde33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions MagentoDotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit bdbde33

Please sign in to comment.