loom-spinner-cli/src/Classes/File/DockerComposeFileBuilder.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2025-04-13 13:11:35 +01:00
<?php
declare(strict_types=1);
namespace Loom\Spinner\Classes\File;
use Loom\Spinner\Classes\Config\Config;
use Loom\Utility\FilePath\FilePath;
2025-04-13 13:11:35 +01:00
use Symfony\Component\Console\Input\InputInterface;
class DockerComposeFileBuilder extends AbstractFileBuilder
{
/**
* @throws \Exception
*/
public function __construct(Config $config)
{
return parent::__construct($config->getDataDirectory() . '/docker-compose.yaml', $config);
2025-04-13 13:11:35 +01:00
}
2025-04-13 20:07:48 +01:00
/**
* @throws \Exception
*/
2025-04-13 13:11:35 +01:00
public function build(InputInterface $input): DockerComposeFileBuilder
{
$this->content = $this->config->getConfigFileContents('php.yaml');
2025-04-13 13:11:35 +01:00
if ($this->config->isDatabaseEnabled($input) && in_array($this->config->getDatabaseDriver($input), ['sqlite3', 'sqlite'])) {
$this->addSqliteDatabaseConfig();
}
2025-04-13 20:07:48 +01:00
if ($this->config->isServerEnabled($input)) {
$this->addNginxConfig();
}
2025-04-13 13:11:35 +01:00
return $this;
}
2025-04-13 20:07:48 +01:00
private function addNginxConfig(): void
{
$this->content .= str_replace(
'services:',
'',
$this->config->getConfigFileContents('nginx.yaml')
2025-04-13 20:07:48 +01:00
);
$this->content = str_replace(
'./nginx/conf.d',
$this->config->getConfigFilePath('nginx/conf.d'),
2025-04-13 20:07:48 +01:00
$this->content
);
}
private function addSqliteDatabaseConfig(): void
{
$sqlLiteConfig = $this->config->getConfigFileContents('sqlite.yaml');
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
$this->content .= $sqlLiteConfig;
}
2025-04-13 13:11:35 +01:00
}