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-23 23:30:51 +01:00
|
|
|
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
|
|
|
|
{
|
2025-04-23 23:30:51 +01:00
|
|
|
$this->content = $this->config->getConfigFileContents('php.yaml');
|
2025-04-13 13:11:35 +01:00
|
|
|
|
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:',
|
|
|
|
'',
|
2025-04-23 23:30:51 +01:00
|
|
|
$this->config->getConfigFileContents('nginx.yaml')
|
2025-04-13 20:07:48 +01:00
|
|
|
);
|
|
|
|
$this->content = str_replace(
|
|
|
|
'./nginx/conf.d',
|
2025-04-23 23:30:51 +01:00
|
|
|
$this->config->getConfigFilePath('nginx/conf.d'),
|
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 23:30:51 +01:00
|
|
|
$sqlLiteConfig = $this->config->getConfigFileContents('sqlite.yaml');
|
2025-04-14 04:32:30 +01:00
|
|
|
$sqlLiteConfig = str_replace('volumes:', '', $sqlLiteConfig);
|
|
|
|
$this->content .= $sqlLiteConfig;
|
|
|
|
}
|
2025-04-13 13:11:35 +01:00
|
|
|
}
|