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

60 lines
2.1 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Loom\Spinner\Classes\File;
use Loom\Spinner\Classes\Config\Config;
use Loom\Spinner\Classes\File\Interface\DataPathInterface;
use Symfony\Component\Console\Input\InputInterface;
class PHPDockerFileBuilder extends AbstractFileBuilder
{
/**
* @throws \Exception
*/
public function __construct(Config $config)
{
$projectPhpFpmDockerfile = $config->getFilePath('projectPhpFpmDockerfile');
if (!$projectPhpFpmDockerfile instanceof SpinnerFilePath) {
throw new \Exception('Project PHP-FPM Dockerfile not found');
}
return parent::__construct($projectPhpFpmDockerfile, $config);
}
/**
* @throws \Exception
*/
public function build(InputInterface $input): PHPDockerFileBuilder
{
$this->setInitialContent();
$this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content);
if ($this->config->isNodeEnabled($input)) {
$this->addNewLine();
$this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath());
$this->content = str_replace('${NODE_VERSION}', (string) $this->config->getNodeVersion($input), $this->content);
}
if ($this->config->isXdebugEnabled($input)) {
$this->addNewLine();
$this->content .= file_get_contents($this->config->getFilePaths()->get('xdebugDockerfileTemplate')->getAbsolutePath());
file_put_contents(
(new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/xdebug.ini', $input->getArgument('name'))))->getProvidedPath(),
file_get_contents($this->config->getFilePaths()->get('xdebugIniTemplate')->getAbsolutePath())
);
}
return $this;
}
private function setInitialContent(): void
{
$this->content = file_get_contents(
2025-04-13 20:07:48 +01:00
$this->config->getFilePaths()->get(DataPathInterface::CONFIG_PHP_FPM_DOCKERFILE)->getAbsolutePath()
);
}
}