1111
1212namespace Symfony \Flex \Configurator ;
1313
14+ use Composer \Composer ;
15+ use Composer \IO \IOInterface ;
1416use Symfony \Flex \Lock ;
17+ use Symfony \Flex \Options ;
1518use Symfony \Flex \Recipe ;
1619use Symfony \Flex \Update \RecipeUpdate ;
1720
2023 */
2124class EnvConfigurator extends AbstractConfigurator
2225{
26+ private string $ suffix ;
27+
28+ public function __construct (Composer $ composer , IOInterface $ io , Options $ options , string $ suffix = '' )
29+ {
30+ parent ::__construct ($ composer , $ io , $ options );
31+ $ this ->suffix = $ suffix ;
32+ }
33+
2334 public function configure (Recipe $ recipe , $ vars , Lock $ lock , array $ options = [])
2435 {
25- $ this ->write ('Adding environment variable defaults ' );
36+ $ this ->write ('Adding environment variable defaults ' .( '' === $ this -> suffix ? '' : ' ( ' . $ this -> suffix . ' ) ' ) );
2637
2738 $ this ->configureEnvDist ($ recipe , $ vars , $ options ['force ' ] ?? false );
39+
40+ if ('' !== $ this ->suffix ) {
41+ return ;
42+ }
43+
2844 if (!file_exists ($ this ->options ->get ('root-dir ' ).'/ ' .($ this ->options ->get ('runtime ' )['dotenv_path ' ] ?? '.env ' ).'.test ' )) {
2945 $ this ->configurePhpUnit ($ recipe , $ vars , $ options ['force ' ] ?? false );
3046 }
@@ -50,8 +66,9 @@ public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array
5066 private function configureEnvDist (Recipe $ recipe , $ vars , bool $ update )
5167 {
5268 $ dotenvPath = $ this ->options ->get ('runtime ' )['dotenv_path ' ] ?? '.env ' ;
69+ $ files = '' === $ this ->suffix ? [$ dotenvPath .'.dist ' , $ dotenvPath ] : [$ dotenvPath .'. ' .$ this ->suffix ];
5370
54- foreach ([ $ dotenvPath . ' .dist ' , $ dotenvPath ] as $ file ) {
71+ foreach ($ files as $ file ) {
5572 $ env = $ this ->options ->get ('root-dir ' ).'/ ' .$ file ;
5673 if (!is_file ($ env )) {
5774 continue ;
@@ -136,8 +153,9 @@ private function configurePhpUnit(Recipe $recipe, $vars, bool $update)
136153 private function unconfigureEnvFiles (Recipe $ recipe , $ vars )
137154 {
138155 $ dotenvPath = $ this ->options ->get ('runtime ' )['dotenv_path ' ] ?? '.env ' ;
156+ $ files = '' === $ this ->suffix ? [$ dotenvPath , $ dotenvPath .'.dist ' ] : [$ dotenvPath .'. ' .$ this ->suffix ];
139157
140- foreach ([ $ dotenvPath , $ dotenvPath . ' .dist ' ] as $ file ) {
158+ foreach ($ files as $ file ) {
141159 $ env = $ this ->options ->get ('root-dir ' ).'/ ' .$ file ;
142160 if (!file_exists ($ env )) {
143161 continue ;
@@ -205,7 +223,7 @@ private function generateRandomBytes($length = 16)
205223 private function getContentsAfterApplyingRecipe (string $ rootDir , Recipe $ recipe , array $ vars ): array
206224 {
207225 $ dotenvPath = $ this ->options ->get ('runtime ' )['dotenv_path ' ] ?? '.env ' ;
208- $ files = [$ dotenvPath , $ dotenvPath .'.dist ' , 'phpunit.xml.dist ' , 'phpunit.xml ' ];
226+ $ files = '' === $ this -> suffix ? [$ dotenvPath , $ dotenvPath .'.dist ' , 'phpunit.xml.dist ' , 'phpunit.xml ' ] : [ $ dotenvPath . ' . ' . $ this -> suffix ];
209227
210228 if (0 === \count ($ vars )) {
211229 return array_fill_keys ($ files , null );
@@ -222,7 +240,7 @@ private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe,
222240 true
223241 );
224242
225- if (!file_exists ($ rootDir .'/ ' .$ dotenvPath .'.test ' )) {
243+ if ('' === $ this -> suffix && !file_exists ($ rootDir .'/ ' .$ dotenvPath .'.test ' )) {
226244 $ this ->configurePhpUnit (
227245 $ recipe ,
228246 $ vars ,
0 commit comments