File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed
Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -75,4 +75,14 @@ class Paths
7575 * is used when no value is provided to `Services::renderer()`.
7676 */
7777 public string $ viewDirectory = __DIR__ . '/../Views ' ;
78+
79+ /**
80+ * ---------------------------------------------------------------
81+ * ENVIRONMENT DIRECTORY NAME
82+ * ---------------------------------------------------------------
83+ *
84+ * This variable must contain the name of the directory for
85+ * environment files.
86+ */
87+ public string $ environmentDirectory = __DIR__ . '/../../ ' ;
7888}
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ public static function preload(Paths $paths): void
170170 protected static function loadDotEnv (Paths $ paths ): void
171171 {
172172 require_once $ paths ->systemDirectory . '/Config/DotEnv.php ' ;
173- (new DotEnv ($ paths ->appDirectory . ' /../ ' ))->load ();
173+ (new DotEnv ($ paths ->environmentDirectory ))->load ();
174174 }
175175
176176 protected static function defineEnvironment (): void
Original file line number Diff line number Diff line change 1717use CodeIgniter \CLI \CLI ;
1818use CodeIgniter \Config \DotEnv ;
1919use CodeIgniter \Encryption \Encryption ;
20+ use Config \Paths ;
2021
2122/**
2223 * Generates a new encryption key.
@@ -101,7 +102,7 @@ public function run(array $params)
101102 // force DotEnv to reload the new env vars
102103 putenv ('encryption.key ' );
103104 unset($ _ENV ['encryption.key ' ], $ _SERVER ['encryption.key ' ]);
104- $ dotenv = new DotEnv (ROOTPATH );
105+ $ dotenv = new DotEnv (( new Paths ())-> environmentDirectory );
105106 $ dotenv ->load ();
106107
107108 CLI ::write ('Application \'s new encryption key was successfully set. ' , 'green ' );
@@ -155,7 +156,7 @@ protected function confirmOverwrite(array $params): bool
155156 protected function writeNewEncryptionKeyToFile (string $ oldKey , string $ newKey ): bool
156157 {
157158 $ baseEnv = ROOTPATH . 'env ' ;
158- $ envFile = ROOTPATH . '.env ' ;
159+ $ envFile = ( new Paths ())-> environmentDirectory . '.env ' ;
159160
160161 if (! is_file ($ envFile )) {
161162 if (! is_file ($ baseEnv )) {
Original file line number Diff line number Diff line change 1616use CodeIgniter \CLI \BaseCommand ;
1717use CodeIgniter \CLI \CLI ;
1818use CodeIgniter \Config \DotEnv ;
19+ use Config \Paths ;
1920
2021/**
2122 * Command to display the current environment,
@@ -119,7 +120,7 @@ public function run(array $params)
119120 // however we cannot redefine the ENVIRONMENT constant
120121 putenv ('CI_ENVIRONMENT ' );
121122 unset($ _ENV ['CI_ENVIRONMENT ' ], $ _SERVER ['CI_ENVIRONMENT ' ]);
122- (new DotEnv (ROOTPATH ))->load ();
123+ (new DotEnv (( new Paths ())-> environmentDirectory ))->load ();
123124
124125 CLI ::write (sprintf ('Environment is successfully changed to "%s". ' , $ env ), 'green ' );
125126 CLI ::write ('The ENVIRONMENT constant will be changed in the next script execution. ' );
@@ -134,7 +135,7 @@ public function run(array $params)
134135 private function writeNewEnvironmentToEnvFile (string $ newEnv ): bool
135136 {
136137 $ baseEnv = ROOTPATH . 'env ' ;
137- $ envFile = ROOTPATH . '.env ' ;
138+ $ envFile = ( new Paths ())-> environmentDirectory . '.env ' ;
138139
139140 if (! is_file ($ envFile )) {
140141 if (! is_file ($ baseEnv )) {
You can’t perform that action at this time.
0 commit comments