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
75
75
* is used when no value is provided to `Services::renderer()`.
76
76
*/
77
77
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__ . '/../../ ' ;
78
88
}
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ public static function preload(Paths $paths): void
170
170
protected static function loadDotEnv (Paths $ paths ): void
171
171
{
172
172
require_once $ paths ->systemDirectory . '/Config/DotEnv.php ' ;
173
- (new DotEnv ($ paths ->appDirectory . ' /../ ' ))->load ();
173
+ (new DotEnv ($ paths ->environmentDirectory ))->load ();
174
174
}
175
175
176
176
protected static function defineEnvironment (): void
Original file line number Diff line number Diff line change 17
17
use CodeIgniter \CLI \CLI ;
18
18
use CodeIgniter \Config \DotEnv ;
19
19
use CodeIgniter \Encryption \Encryption ;
20
+ use Config \Paths ;
20
21
21
22
/**
22
23
* Generates a new encryption key.
@@ -101,7 +102,7 @@ public function run(array $params)
101
102
// force DotEnv to reload the new env vars
102
103
putenv ('encryption.key ' );
103
104
unset($ _ENV ['encryption.key ' ], $ _SERVER ['encryption.key ' ]);
104
- $ dotenv = new DotEnv (ROOTPATH );
105
+ $ dotenv = new DotEnv (( new Paths ())-> environmentDirectory );
105
106
$ dotenv ->load ();
106
107
107
108
CLI ::write ('Application \'s new encryption key was successfully set. ' , 'green ' );
@@ -155,7 +156,7 @@ protected function confirmOverwrite(array $params): bool
155
156
protected function writeNewEncryptionKeyToFile (string $ oldKey , string $ newKey ): bool
156
157
{
157
158
$ baseEnv = ROOTPATH . 'env ' ;
158
- $ envFile = ROOTPATH . '.env ' ;
159
+ $ envFile = ( new Paths ())-> environmentDirectory . '.env ' ;
159
160
160
161
if (! is_file ($ envFile )) {
161
162
if (! is_file ($ baseEnv )) {
Original file line number Diff line number Diff line change 16
16
use CodeIgniter \CLI \BaseCommand ;
17
17
use CodeIgniter \CLI \CLI ;
18
18
use CodeIgniter \Config \DotEnv ;
19
+ use Config \Paths ;
19
20
20
21
/**
21
22
* Command to display the current environment,
@@ -119,7 +120,7 @@ public function run(array $params)
119
120
// however we cannot redefine the ENVIRONMENT constant
120
121
putenv ('CI_ENVIRONMENT ' );
121
122
unset($ _ENV ['CI_ENVIRONMENT ' ], $ _SERVER ['CI_ENVIRONMENT ' ]);
122
- (new DotEnv (ROOTPATH ))->load ();
123
+ (new DotEnv (( new Paths ())-> environmentDirectory ))->load ();
123
124
124
125
CLI ::write (sprintf ('Environment is successfully changed to "%s". ' , $ env ), 'green ' );
125
126
CLI ::write ('The ENVIRONMENT constant will be changed in the next script execution. ' );
@@ -134,7 +135,7 @@ public function run(array $params)
134
135
private function writeNewEnvironmentToEnvFile (string $ newEnv ): bool
135
136
{
136
137
$ baseEnv = ROOTPATH . 'env ' ;
137
- $ envFile = ROOTPATH . '.env ' ;
138
+ $ envFile = ( new Paths ())-> environmentDirectory . '.env ' ;
138
139
139
140
if (! is_file ($ envFile )) {
140
141
if (! is_file ($ baseEnv )) {
You can’t perform that action at this time.
0 commit comments