Skip to content

Commit e12ec5b

Browse files
author
Benjamin Calef
committed
[v2.0.2] add self-creation of .env file
1 parent bdbde33 commit e12ec5b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

MagentoDotenv.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Zepgram\Component\MagentoDotenv;
66

77
use Symfony\Component\Dotenv\Dotenv as SymfonyDotenv;
8+
use function copy;
9+
use function is_file;
10+
use function touch;
811

912
class MagentoDotenv
1013
{
@@ -32,16 +35,16 @@ class MagentoDotenv
3235
public static function init(): void
3336
{
3437
$dotenvDest = ROOT_DIRECTORY . self::DEST_APP_ETC_DOTENV_FILE;
35-
if (\is_file($dotenvDest)) {
38+
if (is_file($dotenvDest)) {
3639
require_once $dotenvDest;
3740
return;
3841
} else {
3942
$dotenvSrc = ROOT_DIRECTORY . self::SRC_APP_ETC_DOTENV_FILE;
40-
\copy($dotenvSrc, $dotenvDest);
43+
copy($dotenvSrc, $dotenvDest);
4144
}
4245

4346
$magentoBootstrapFile = ROOT_DIRECTORY . self::MAGENTO_BOOTSTRAP_FILE;
44-
if (!\is_file($magentoBootstrapFile)) {
47+
if (!is_file($magentoBootstrapFile)) {
4548
return;
4649
}
4750

@@ -64,6 +67,10 @@ public static function get(
6467
if ($envFilePath !== '') {
6568
$envFilePath = $envFilePath . DIRECTORY_SEPARATOR;
6669
}
70+
$envFile = ROOT_DIRECTORY . $envFilePath . self::ENV_FILE;
71+
if (!is_file($envFile)) {
72+
touch($envFile);
73+
}
6774

6875
$dotenv = new SymfonyDotenv($envKey, $debugKey);
6976
$dotenv->usePutEnv($usePutEnv);

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Simple autoloader to integrate the Symfony Dotenv component into Magento2",
44
"keywords": ["magento2", "environment", "env", "dotenv"],
55
"type": "magento2-component",
6-
"version": "2.0.1",
6+
"version": "2.0.2",
77
"authors":[
88
{
99
"name": "Benjamin Calef",

0 commit comments

Comments
 (0)