@@ -56,7 +56,6 @@ final class MakeDockerDatabase extends AbstractMaker
56
56
public function __construct (FileManager $ fileManager )
57
57
{
58
58
$ this ->fileManager = $ fileManager ;
59
- $ this ->composeFilePath = sprintf ('%s/docker-compose.yaml ' , $ this ->fileManager ->getRootDirectory ());
60
59
}
61
60
62
61
public static function getCommandName (): string
@@ -80,18 +79,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
80
79
{
81
80
$ io ->section ('- Docker Compose Setup- ' );
82
81
83
- $ composeFileContents = '' ;
84
- $ statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated! ' ;
85
-
86
- if ($ this ->fileManager ->fileExists ($ this ->composeFilePath )) {
87
- $ composeFileContents = $ this ->fileManager ->getFileContents ($ this ->composeFilePath );
88
-
89
- $ statusMessage = 'We found your existing docker-compose.yaml: Let \'s update it! ' ;
90
- }
91
-
92
- $ io ->text ($ statusMessage );
93
-
94
- $ this ->composeFileManipulator = new ComposeFileManipulator ($ composeFileContents );
82
+ $ this ->composeFileManipulator = new ComposeFileManipulator ($ this ->getComposeFileContents ($ io ));
95
83
96
84
$ io ->newLine ();
97
85
@@ -185,4 +173,34 @@ private function checkForPDOSupport(string $databaseType, ConsoleStyle $io): voi
185
173
);
186
174
}
187
175
}
176
+
177
+ /**
178
+ * Determines and sets the correct Compose File Path and retrieves its contents
179
+ * if the file exists else an empty string.
180
+ */
181
+ private function getComposeFileContents (ConsoleStyle $ io ): string
182
+ {
183
+ $ this ->composeFilePath = sprintf ('%s/docker-compose.yaml ' , $ this ->fileManager ->getRootDirectory ());
184
+
185
+ $ composeFileExists = false ;
186
+ $ statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated! ' ;
187
+ $ contents = '' ;
188
+
189
+ foreach (['.yml ' , '.yaml ' ] as $ extension ) {
190
+ $ composeFilePath = sprintf ('%s/docker-compose%s ' , $ this ->fileManager ->getRootDirectory (), $ extension );
191
+
192
+ if (!$ composeFileExists && $ this ->fileManager ->fileExists ($ composeFilePath )) {
193
+ $ composeFileExists = true ;
194
+
195
+ $ statusMessage = sprintf ('We found your existing docker-compose%s: Let \'s update it! ' , $ extension );
196
+
197
+ $ this ->composeFilePath = $ composeFilePath ;
198
+ $ contents = $ this ->fileManager ->getFileContents ($ composeFilePath );
199
+ }
200
+ }
201
+
202
+ $ io ->text ($ statusMessage );
203
+
204
+ return $ contents ;
205
+ }
188
206
}
0 commit comments