Skip to content

Commit

Permalink
[v2.0.2] add self-creation of .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Calef committed Jun 12, 2023
1 parent bdbde33 commit e12ec5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions MagentoDotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace Zepgram\Component\MagentoDotenv;

use Symfony\Component\Dotenv\Dotenv as SymfonyDotenv;
use function copy;
use function is_file;
use function touch;

class MagentoDotenv
{
Expand Down Expand Up @@ -32,16 +35,16 @@ class MagentoDotenv
public static function init(): void
{
$dotenvDest = ROOT_DIRECTORY . self::DEST_APP_ETC_DOTENV_FILE;
if (\is_file($dotenvDest)) {
if (is_file($dotenvDest)) {
require_once $dotenvDest;
return;
} else {
$dotenvSrc = ROOT_DIRECTORY . self::SRC_APP_ETC_DOTENV_FILE;
\copy($dotenvSrc, $dotenvDest);
copy($dotenvSrc, $dotenvDest);
}

$magentoBootstrapFile = ROOT_DIRECTORY . self::MAGENTO_BOOTSTRAP_FILE;
if (!\is_file($magentoBootstrapFile)) {
if (!is_file($magentoBootstrapFile)) {
return;
}

Expand All @@ -64,6 +67,10 @@ public static function get(
if ($envFilePath !== '') {
$envFilePath = $envFilePath . DIRECTORY_SEPARATOR;
}
$envFile = ROOT_DIRECTORY . $envFilePath . self::ENV_FILE;
if (!is_file($envFile)) {
touch($envFile);
}

$dotenv = new SymfonyDotenv($envKey, $debugKey);
$dotenv->usePutEnv($usePutEnv);
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.1",
"version": "2.0.2",
"authors":[
{
"name": "Benjamin Calef",
Expand Down

0 comments on commit e12ec5b

Please sign in to comment.