Render a simple template

This commit is contained in:
Oliver Davies 2023-01-19 18:37:13 +00:00
parent c476543f5c
commit 31614e0f58
5 changed files with 82 additions and 67 deletions

View file

@ -1,3 +1,8 @@
{
"directories": [
"src",
"templates",
"vendor"
],
"main": "build-config.php"
}

View file

@ -2,7 +2,8 @@
"require": {
"twig/twig": "^3.5",
"symfony/console": "^6.2",
"symfony/yaml": "^6.2"
"symfony/yaml": "^6.2",
"symfony/filesystem": "^6.2"
},
"require-dev": {
"humbug/box": "^4.2",

128
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "10bdf6712c1d4ee4e01f212c41080a07",
"content-hash": "cd4297546e12f0fef941f564d6d9b4c4",
"packages": [
{
"name": "psr/container",
@ -222,6 +222,69 @@
],
"time": "2022-11-25T10:21:52+00:00"
},
{
"name": "symfony/filesystem",
"version": "v6.2.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/50b2523c874605cf3d4acf7a9e2b30b6a440a016",
"reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v6.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-20T13:01:27+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.27.0",
@ -2734,69 +2797,6 @@
],
"time": "2022-11-25T10:21:52+00:00"
},
{
"name": "symfony/filesystem",
"version": "v6.2.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/50b2523c874605cf3d4acf7a9e2b30b6a440a016",
"reference": "50b2523c874605cf3d4acf7a9e2b30b6a440a016",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v6.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-20T13:01:27+00:00"
},
{
"name": "symfony/finder",
"version": "v6.2.3",

View file

@ -9,7 +9,10 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
#[AsCommand(
description: 'Build configuration files',
@ -25,8 +28,11 @@ final class BuildConfigurationCommand extends Command
$io = new SymfonyStyle($input, $output);
$io->info("Building configuration for {$buildYaml['name']}.");
// Parse its contents.
// Generate the appropriate configuration files.
$twig = new Environment(new FilesystemLoader([__DIR__.'/../../../templates']));
$output = $twig->render('test.twig', $buildYaml);
$fs = new Filesystem();
$fs->dumpFile('test.txt', $output);
//
return Command::SUCCESS;
}

3
templates/test.twig Normal file
View file

@ -0,0 +1,3 @@
name: {{ name }}
type: {{ type }}
language: {{ language }}