From 56becd3e9cf6fd49f7861b507f16988d697528ca Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 18 Feb 2021 01:25:19 -0500 Subject: [PATCH] [MakeDocker] add support for .yml docker-compose files --- src/Maker/MakeDockerDatabase.php | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/Maker/MakeDockerDatabase.php b/src/Maker/MakeDockerDatabase.php index 6f3ffa0a9..f20adab03 100644 --- a/src/Maker/MakeDockerDatabase.php +++ b/src/Maker/MakeDockerDatabase.php @@ -56,7 +56,6 @@ final class MakeDockerDatabase extends AbstractMaker public function __construct(FileManager $fileManager) { $this->fileManager = $fileManager; - $this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory()); } public static function getCommandName(): string @@ -80,18 +79,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma { $io->section('- Docker Compose Setup-'); - $composeFileContents = ''; - $statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!'; - - if ($this->fileManager->fileExists($this->composeFilePath)) { - $composeFileContents = $this->fileManager->getFileContents($this->composeFilePath); - - $statusMessage = 'We found your existing docker-compose.yaml: Let\'s update it!'; - } - - $io->text($statusMessage); - - $this->composeFileManipulator = new ComposeFileManipulator($composeFileContents); + $this->composeFileManipulator = new ComposeFileManipulator($this->getComposeFileContents($io)); $io->newLine(); @@ -185,4 +173,34 @@ private function checkForPDOSupport(string $databaseType, ConsoleStyle $io): voi ); } } + + /** + * Determines and sets the correct Compose File Path and retrieves its contents + * if the file exists else an empty string. + */ + private function getComposeFileContents(ConsoleStyle $io): string + { + $this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory()); + + $composeFileExists = false; + $statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!'; + $contents = ''; + + foreach (['.yml', '.yaml'] as $extension) { + $composeFilePath = sprintf('%s/docker-compose%s', $this->fileManager->getRootDirectory(), $extension); + + if (!$composeFileExists && $this->fileManager->fileExists($composeFilePath)) { + $composeFileExists = true; + + $statusMessage = sprintf('We found your existing docker-compose%s: Let\'s update it!', $extension); + + $this->composeFilePath = $composeFilePath; + $contents = $this->fileManager->getFileContents($composeFilePath); + } + } + + $io->text($statusMessage); + + return $contents; + } }