build-configs/src/Console/Command/BuildConfigurationCommand.php

47 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace OliverDaviesLtd\BuildConfiguration\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
2023-01-19 18:37:13 +00:00
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
2023-01-19 18:37:13 +00:00
use Twig\Environment;
#[AsCommand(
description: 'Build configuration files',
name: 'build-configuration'
)]
final class BuildConfigurationCommand extends Command
{
2023-01-19 18:53:42 +00:00
private const LANGUAGE_PHP = 'php';
public function __construct(
private Environment $twig,
private Filesystem $filesystem,
) {
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output)
{
2023-01-19 18:53:42 +00:00
$io = new SymfonyStyle($input, $output);
$buildYaml = Yaml::parseFile(getcwd().'/build.yaml');
$io->info("Building configuration for {$buildYaml['name']}.");
2023-01-19 18:53:42 +00:00
if ($buildYaml['language'] === self::LANGUAGE_PHP) {
$this->filesystem->dumpFile('Dockerfile', $this->twig->render('php/Dockerfile.twig', $buildYaml));
}
2023-01-19 18:37:13 +00:00
return Command::SUCCESS;
}
}