@@ -70,21 +70,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
70
70
return 1 ;
71
71
}
72
72
73
- $ envFiles = $ this ->getEnvFiles ();
74
- $ availableFiles = array_filter ($ envFiles , fn (string $ file ) => is_file ($ this ->getFilePath ($ file )));
73
+ $ filePath = $ _SERVER ['SYMFONY_DOTENV_PATH ' ] ?? $ this ->projectDirectory .\DIRECTORY_SEPARATOR .'.env ' ;
75
74
76
- if (\in_array ('.env.local.php ' , $ availableFiles , true )) {
77
- $ io ->warning ('Due to existing dump file (.env.local.php) all other dotenv files are skipped. ' );
75
+ $ envFiles = $ this ->getEnvFiles ($ filePath );
76
+ $ availableFiles = array_filter ($ envFiles , fn (string $ file ) => is_file ($ file ));
77
+
78
+ if (\in_array (sprintf ('%s.local.php ' , $ filePath ), $ availableFiles , true )) {
79
+ $ io ->warning (sprintf ('Due to existing dump file (%s.local.php) all other dotenv files are skipped. ' , $ this ->getRelativeName ($ filePath )));
78
80
}
79
81
80
- if (is_file ($ this -> getFilePath ( ' .env ' )) && is_file ($ this -> getFilePath ( ' .env. dist ' ))) {
81
- $ io ->warning ('The file .env. dist gets skipped due to the existence of .env. ' );
82
+ if (is_file ($ filePath ) && is_file (sprintf ( ' %s. dist ', $ filePath ))) {
83
+ $ io ->warning (sprintf ( 'The file %s. dist gets skipped due to the existence of %1$s. ' , $ this -> getRelativeName ( $ filePath )) );
82
84
}
83
85
84
86
$ io ->section ('Scanned Files (in descending priority) ' );
85
- $ io ->listing (array_map (static fn (string $ envFile ) => \in_array ($ envFile , $ availableFiles , true )
86
- ? sprintf ('<fg=green>✓</> %s ' , $ envFile )
87
- : sprintf ('<fg=red>⨯</> %s ' , $ envFile ), $ envFiles ));
87
+ $ io ->listing (array_map (fn (string $ envFile ) => \in_array ($ envFile , $ availableFiles , true )
88
+ ? sprintf ('<fg=green>✓</> %s ' , $ this -> getRelativeName ( $ envFile) )
89
+ : sprintf ('<fg=red>⨯</> %s ' , $ this -> getRelativeName ( $ envFile) ), $ envFiles ));
88
90
89
91
$ nameFilter = $ input ->getArgument ('filter ' );
90
92
$ variables = $ this ->getVariables ($ availableFiles , $ nameFilter );
@@ -93,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
93
95
94
96
if ($ variables || null === $ nameFilter ) {
95
97
$ io ->table (
96
- array_merge (['Variable ' , 'Value ' ], $ availableFiles ),
98
+ array_merge (['Variable ' , 'Value ' ], array_map ( $ this -> getRelativeName (...), $ availableFiles) ),
97
99
$ this ->getVariables ($ availableFiles , $ nameFilter )
98
100
);
99
101
@@ -147,36 +149,38 @@ private function getAvailableVars(): array
147
149
return $ vars ;
148
150
}
149
151
150
- private function getEnvFiles (): array
152
+ private function getEnvFiles (string $ filePath ): array
151
153
{
152
154
$ files = [
153
- ' .env. local.php ' ,
154
- sprintf ('.env. %s.local ' , $ this ->kernelEnvironment ),
155
- sprintf ('.env. %s ' , $ this ->kernelEnvironment ),
155
+ sprintf ( ' %s. local.php ', $ filePath ) ,
156
+ sprintf ('%s. %s.local ' , $ filePath , $ this ->kernelEnvironment ),
157
+ sprintf ('%s. %s ' , $ filePath , $ this ->kernelEnvironment ),
156
158
];
157
159
158
160
if ('test ' !== $ this ->kernelEnvironment ) {
159
- $ files [] = ' .env. local ' ;
161
+ $ files [] = sprintf ( ' %s. local ', $ filePath ) ;
160
162
}
161
163
162
- if (!is_file ($ this -> getFilePath ( ' .env ' )) && is_file ($ this -> getFilePath ( ' .env. dist ' ))) {
163
- $ files [] = ' .env. dist ' ;
164
+ if (!is_file ($ filePath ) && is_file (sprintf ( ' %s. dist ', $ filePath ))) {
165
+ $ files [] = sprintf ( ' %s. dist ', $ filePath ) ;
164
166
} else {
165
- $ files [] = ' .env ' ;
167
+ $ files [] = $ filePath ;
166
168
}
167
169
168
170
return $ files ;
169
171
}
170
172
171
- private function getFilePath (string $ file ): string
173
+ private function getRelativeName (string $ filePath ): string
172
174
{
173
- return $ this ->projectDirectory .\DIRECTORY_SEPARATOR .$ file ;
175
+ if (str_starts_with ($ filePath , $ this ->projectDirectory )) {
176
+ return substr ($ filePath , \strlen ($ this ->projectDirectory ) + 1 );
177
+ }
178
+
179
+ return basename ($ filePath );
174
180
}
175
181
176
- private function loadValues (string $ file ): array
182
+ private function loadValues (string $ filePath ): array
177
183
{
178
- $ filePath = $ this ->getFilePath ($ file );
179
-
180
184
if (str_ends_with ($ filePath , '.php ' )) {
181
185
return include $ filePath ;
182
186
}
0 commit comments