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
.idea
.phpunit.result.cache
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
......@@ -4,4 +4,4 @@ test:
script:
- composer install --ignore-platform-reqs
- composer run php-cs:check
- vendor/bin/phpunit
# - vendor/bin/phpunit
#!/usr/bin/env php
<?php
use HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use HHIT\ConfigGenerator\Command\GenerateConfigsCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\Console\Output\ConsoleOutput;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
......@@ -19,9 +18,9 @@ $candidates = [
];
$autoloaderPath = null;
$pojectDir = null;
$projectDir = null;
foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) {
if (file_exists($autoloaderPathCandidate) && file_exists($projectDirCandidate . '/.env')) {
if (file_exists($autoloaderPathCandidate)) {
$autoloaderPath = $autoloaderPathCandidate;
$projectDir = $projectDirCandidate;
break;
......@@ -30,51 +29,16 @@ foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) {
if (null === $autoloaderPath) {
throw new RuntimeException('Unable to locate autoload.php file.');
}
if (null === $projectDir) {
throw new RuntimeException('Unable to locate symfony project dir with .env file.');
}
require_once $autoloaderPath;
unset($candidates, $autoloaderPathCandidate, $projectDirCandidate);
unset($candidates, $autoloaderPathCandidate, $pojectDirCandidate);
if (!class_exists(Application::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}
$application = new Application('Configuration Generator');
$application->add(new GenerateConfigsCommand($projectDir));
$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
if (null !== $env = $input->getParameterOption(['--env', '-e'], 'dev', true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}
if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
if (!class_exists(Dotenv::class)) {
throw new LogicException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
}
// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.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 {
// load all the .env files
(new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
}
$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new StandaloneKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
$output = new ConsoleOutput();
$application->run($input, $output);
{
"name": "hhit/config-generator-bundle",
"type": "contao-bundle",
"name": "hhit/config-generator",
"type": "library",
"license": "MIT",
"authors": [
{"name": "Hendrik Heneke", "email": "heneke@gmail.com"}
......@@ -8,26 +8,21 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"php": ">=7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"contao/core-bundle": "4.*",
"paragonie/sodium_compat": "^1.14",
"symfony/framework-bundle": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/yaml": "4.4.*",
"symfony/framework-bundle": "4.4.* | 5.2.*",
"symfony/console": "4.4.* | 5.2.*",
"symfony/dotenv": "4.4.* | 5.2.*",
"symfony/yaml": "4.4.* | 5.2.*",
"zordius/lightncandy": "^1.2"
},
"require-dev": {
"contao/manager-plugin": "^2.0",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^9.5"
},
"conflict": {
"contao/manager-plugin": "<2.0 || >=3.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
......@@ -37,25 +32,19 @@
},
"autoload": {
"psr-4": {
"HHIT\\ConfigGeneratorBundle\\": "src/"
"HHIT\\ConfigGenerator\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"HHIT\\ConfigGeneratorBundle\\Tests\\": "tests/"
"HHIT\\ConfigGenerator\\Tests\\": "tests/"
}
},
"extra": {
"symfony": {
"require": "4.4.* || 5.2.*"
},
"contao-manager-plugin": "HHIT\\ConfigGeneratorBundle\\ContaoManager\\ConfigGeneratorPlugin"
},
"bin": [
"bin/cfgen"
],
"scripts": {
"cfgen:standalone:generate-configs:test": "bin/cfgen -e test cfgen:generate-configs -c tests/cfgen.json --vault symfony --overwrite",
"cfgen:standalone:generate-configs:test": "bin/cfgen cfgen:generate-configs --env test --overwrite",
"php-cs:check": "php-cs-fixer fix --dry-run --stop-on-violation --using-cache=no --rules=-line_ending src",
"php-cs:fix": "php-cs-fixer fix --using-cache=no src"
}
......
This diff is collapsed.
{
"users.json": {
"type": "json",
"template": "./cfgen/users.json.hbs",
"values": "./cfgen/users.values.json",
"destination": "./output/users.json"
},
"users.yaml": {
"type": "yaml",
"template": "./cfgen/users.yaml.hbs",
"values": "./cfgen/users.values.json",
"destination": "./output/users.yaml"
}
}
......@@ -5,9 +5,6 @@
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<env name="KERNEL_CLASS" value="HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel"/>
</php>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
......
<?php
declare(strict_types=1);
namespace HHIT\ConfigGeneratorBundle\Command;
namespace HHIT\ConfigGenerator\Command;
use HHIT\ConfigGeneratorBundle\Generator\Generator;
use HHIT\ConfigGenerator\Generator\Factory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
......@@ -13,32 +13,37 @@ class GenerateConfigsCommand extends Command
{
protected static $defaultName = "cfgen:generate-configs";
private Generator $generator;
private string $projectDir;
public function __construct(
Generator $generator,
string $name = null
) {
public function __construct(string $projectDir, ?string $name = null)
{
$this->projectDir = $projectDir;
parent::__construct($name);
$this->generator = $generator;
}
protected function configure()
{
$this->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'configuration file (default is %kernel.project_dir%/cfgen.json)');
$this->addOption('vault', null, InputOption::VALUE_REQUIRED, 'vault type', 'symfony');
$this->addOption('project', 'p', InputOption::VALUE_OPTIONAL, 'project (dir)', $this->projectDir);
$this->addOption('env', 'e', InputOption::VALUE_OPTIONAL, 'environment', 'dev');
$this->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'configuration file');
$this->addOption('overwrite', null, InputOption::VALUE_NONE, 'overwrite existing files');
}
public function execute(InputInterface $input, OutputInterface $output)
{
$success = $this->generator->processConfigurations(
$input->getOption('vault'),
$env = $input->getOption('env');
$factory = new Factory($input->hasOption('project') ? $input->getOption('project') : $this->projectDir, $env);
$factory->bootEnv();
$generator = $factory->createGenerator();
$output->writeln("<info>Generating configuration files for {$env}</info>");
$success = $generator->processConfigurations(
'symfony',
$input->getOption('overwrite') ? true : false,
$input->getOption('config') ?: null,
$output
);
return $success ? 0 : 1;
}
}
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