2025-04-13 13:11:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Loom\Spinner\Classes\File;
|
|
|
|
|
|
|
|
use Loom\Spinner\Classes\Config\Config;
|
2025-04-23 18:07:35 +01:00
|
|
|
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)
|
|
|
|
{
|
2025-04-13 13:35:39 +01:00
|
|
|
$projectDockerCompose = $config->getFilePaths()->get('projectDockerCompose');
|
2025-04-13 13:11:35 +01:00
|
|
|
|
2025-04-23 18:07:35 +01:00
|
|
|
if (!$projectDockerCompose instanceof FilePath) {
|
2025-04-13 13:11:35 +01:00
|
|
|
throw new \Exception('Project Docker Compose file path not found.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::__construct($projectDockerCompose, $config);
|
|
|
|
}
|
|
|
|
|
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 = file_get_contents(
|
|
|
|
$this->config->getFilePaths()->get('phpYamlTemplate')->getAbsolutePath()
|
|
|
|
);
|
|
|
|
|
2025-04-14 04:32:30 +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:',
|
|
|
|
'',
|
|
|
|
file_get_contents(
|
|
|
|
$this->config->getFilePaths()->get('nginxYamlTemplate')->getAbsolutePath()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->content = str_replace(
|
|
|
|
'./nginx/conf.d',
|
2025-04-23 18:07:35 +01:00
|
|
|
(new FilePath('config/nginx/conf.d'))->getAbsolutePath(),
|
2025-04-13 20:07:48 +01:00
|
|
|
$this->content
|
|
|
|
);
|
|
|
|
}
|
2025-04-14 04:32:30 +01:00
|
|
|
|
|
|
|
private function addSqliteDatabaseConfig(): void
|
|
|
|
{
|
2025-04-23 18:07:35 +01:00
|
|
|
$sqlLiteConfig = file_get_contents((new FilePath('config/sqlite.yaml'))->getAbsolutePath());
|
2025-04-14 04:32:30 +01:00
|
|
|
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
|
|
|
|
$this->content .= $sqlLiteConfig;
|
|
|
|
}
|
2025-04-13 13:11:35 +01:00
|
|
|
}
|