Commit 0c3008e8 authored by Hendrik Heneke's avatar Hendrik Heneke
Browse files

Switched back to standalone application and renamed package.

parent 604bc534
Pipeline #367 passed with stage
in 18 seconds
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ConfigGeneratorBundle extends Bundle
{
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\ContaoManager;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use HHIT\ConfigGeneratorBundle\ConfigGeneratorBundle;
class ConfigGeneratorPlugin implements BundlePluginInterface
{
public function getBundles(ParserInterface $parser)
{
return [BundleConfig::create(ConfigGeneratorBundle::class)];
}
}
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
class ConfigGeneratorExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yaml');
}
}
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Compiler; namespace HHIT\ConfigGenerator\Generator\Compiler;
use HHIT\ConfigGeneratorBundle\Generator\IO\File; use HHIT\ConfigGenerator\Generator\IO\File;
use HHIT\ConfigGeneratorBundle\Generator\IO\FileReader; use HHIT\ConfigGenerator\Generator\IO\FileReader;
use HHIT\ConfigGeneratorBundle\Generator\Values\ValuesLoader; use HHIT\ConfigGenerator\Generator\Values\ValuesLoader;
use LightnCandy\LightnCandy; use LightnCandy\LightnCandy;
class Compiler extends FileReader class Compiler extends FileReader
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Definition; namespace HHIT\ConfigGenerator\Generator\Definition;
use HHIT\ConfigGeneratorBundle\Generator\IO\File; use HHIT\ConfigGenerator\Generator\IO\File;
use HHIT\ConfigGeneratorBundle\Generator\IO\Path; use HHIT\ConfigGenerator\Generator\IO\Path;
class Definition class Definition
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Definition; namespace HHIT\ConfigGenerator\Generator\Definition;
use HHIT\ConfigGeneratorBundle\Generator\IO\File; use HHIT\ConfigGenerator\Generator\IO\File;
use HHIT\ConfigGeneratorBundle\Generator\IO\JsonReader; use HHIT\ConfigGenerator\Generator\IO\JsonReader;
use HHIT\ConfigGeneratorBundle\Generator\IO\Path; use HHIT\ConfigGenerator\Generator\IO\Path;
use HHIT\ConfigGeneratorBundle\Generator\IO\ReaderFactory; use HHIT\ConfigGenerator\Generator\IO\ReaderFactory;
use HHIT\ConfigGeneratorBundle\Generator\StringUtils; use HHIT\ConfigGenerator\Generator\StringUtils;
class DefinitionReader class DefinitionReader
{ {
......
<?php
declare(strict_types=1);
namespace HHIT\ConfigGenerator\Generator;
use HHIT\ConfigGenerator\Generator\Definition\DefinitionReader;
use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderFactory;
use HHIT\ConfigGenerator\Generator\Secrets\SymfonyVaultSecretProvider;
use HHIT\ConfigGenerator\Generator\Validator\ValidatorFactory;
use HHIT\ConfigGenerator\Generator\Values\ValuesLoaderFactory;
use Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault;
use Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault;
use Symfony\Component\Dotenv\Dotenv;
class Factory
{
private string $projectDir;
private string $env;
public function __construct(string $projectDir, string $env = 'dev')
{
$this->projectDir = $projectDir;
$this->env = $env;
}
private function createDefinitionReader(): DefinitionReader
{
return new DefinitionReader($this->projectDir);
}
function createSodiumVault(): SodiumVault
{
return $this->createSodiumVaultInternal($this->projectDir . '/config/secrets/' . $this->env);
}
private function createSodiumVaultInternal(string $secretsDir, $decryptionKey = null): SodiumVault
{
return new SodiumVault($secretsDir, $decryptionKey);
}
private function createDotenvVault(string $dotenvFile): DotenvVault
{
return new DotenvVault($dotenvFile);
}
private function createSymfonyVaultSecretProvider(): SymfonyVaultSecretProvider
{
return new SymfonyVaultSecretProvider(
$this->createSodiumVault(),
$this->createDotenvVault($this->projectDir . '/.env')
);
}
private function createSecretProviderFactory(): SecretProviderFactory
{
return new SecretProviderFactory($this->createSymfonyVaultSecretProvider());
}
private function createValuesLoaderFactory(): ValuesLoaderFactory
{
return new ValuesLoaderFactory($this->createSecretProviderFactory());
}
private function createValidatorFactory(): ValidatorFactory
{
return new ValidatorFactory();
}
function createGenerator(): Generator
{
return new Generator(
$this->createDefinitionReader(),
$this->createValuesLoaderFactory(),
$this->createValidatorFactory(),
);
}
function bootEnv()
{
if (is_array($env = @include $this->projectDir . '/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
(new Dotenv(false))->populate($env);
} else {
(new Dotenv(false))->loadEnv($this->projectDir . '/.env');
}
}
}
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator; namespace HHIT\ConfigGenerator\Generator;
use HHIT\ConfigGeneratorBundle\Generator\Compiler\Compiler; use HHIT\ConfigGenerator\Generator\Compiler\Compiler;
use HHIT\ConfigGeneratorBundle\Generator\Definition\DefinitionReader; use HHIT\ConfigGenerator\Generator\Definition\DefinitionReader;
use HHIT\ConfigGeneratorBundle\Generator\IO\FileWriter; use HHIT\ConfigGenerator\Generator\IO\FileWriter;
use HHIT\ConfigGeneratorBundle\Generator\Definition\Definition; use HHIT\ConfigGenerator\Generator\Definition\Definition;
use HHIT\ConfigGeneratorBundle\Generator\Validator\ValidationException; use HHIT\ConfigGenerator\Generator\Validator\ValidationException;
use HHIT\ConfigGeneratorBundle\Generator\Validator\ValidatorFactory; use HHIT\ConfigGenerator\Generator\Validator\ValidatorFactory;
use HHIT\ConfigGeneratorBundle\Generator\Values\ValuesLoaderFactory; use HHIT\ConfigGenerator\Generator\Values\ValuesLoaderFactory;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class Generator class Generator
...@@ -39,7 +39,7 @@ class Generator ...@@ -39,7 +39,7 @@ class Generator
/** /**
* @var $definition Definition * @var $definition Definition
*/ */
$this->writeln($output, "<info>Processing configuration {$definition->getId()}</info>"); $this->writeln($output, "<info>- processing {$definition->getId()}</info>");
try { try {
$valuesLoader = $this->valuesLoaderFactory->create($definition->getValuesFile(), $vaultType); $valuesLoader = $this->valuesLoaderFactory->create($definition->getValuesFile(), $vaultType);
...@@ -50,14 +50,15 @@ class Generator ...@@ -50,14 +50,15 @@ class Generator
$definition->getDestinationFile()->parent(false); $definition->getDestinationFile()->parent(false);
$writer = new FileWriter($definition->getDestinationFile()); $writer = new FileWriter($definition->getDestinationFile());
$writer->write($compiler->compile(), $overwrite); $writer->write($compiler->compile(), $overwrite);
$this->writeln($output, "<info>-- configuration written to {$definition->getDestinationFile()->asString()}</info>");
$success[] = true; $success[] = true;
} catch (ValidationException $ve) { } catch (ValidationException $ve) {
$this->writeln($output, "<error>generated content for {$definition->getId()} is invalid: {$ve->getMessage()}</error>"); $this->writeln($output, "<error>== generated content for {$definition->getId()} is invalid: {$ve->getMessage()}</error>");
throw $ve; throw $ve;
} }
} catch (\Throwable $t) { } catch (\Throwable $t) {
if (!$t instanceof ValidationException) { if (!$t instanceof ValidationException) {
$this->writeln($output, "<error>generating configuration file {$definition->getId()} failed: {$t->getMessage()}</error>"); $this->writeln($output, "<error>== generating configuration file {$definition->getId()} failed: {$t->getMessage()}</error>");
} }
$success[] = false; $success[] = false;
} }
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
class Directory extends Path class Directory extends Path
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
class File extends Path class File extends Path
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
class FileReader class FileReader
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
class FileWriter class FileWriter
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
class JsonReader extends FileReader class JsonReader extends FileReader
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\IO; namespace HHIT\ConfigGenerator\Generator\IO;
use HHIT\ConfigGeneratorBundle\Generator\StringUtils; use HHIT\ConfigGenerator\Generator\StringUtils;
abstract class Path abstract class Path
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Secrets; namespace HHIT\ConfigGenerator\Generator\Secrets;
class SecretProviderFactory class SecretProviderFactory
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Secrets; namespace HHIT\ConfigGenerator\Generator\Secrets;
interface SecretProviderInterface interface SecretProviderInterface
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Secrets; namespace HHIT\ConfigGenerator\Generator\Secrets;
use Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault; use Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault;
use Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault; use Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault;
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator; namespace HHIT\ConfigGenerator\Generator;
class StringUtils class StringUtils
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Validator; namespace HHIT\ConfigGenerator\Generator\Validator;
class JSONValidator implements ValidatorInterface class JSONValidator implements ValidatorInterface
{ {
......
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Generator\Validator; namespace HHIT\ConfigGenerator\Generator\Validator;
use Throwable; use Throwable;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment