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 .idea
.phpunit.result.cache .phpunit.result.cache
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/ /vendor/
###< symfony/framework-bundle ###
...@@ -4,4 +4,4 @@ test: ...@@ -4,4 +4,4 @@ test:
script: script:
- composer install --ignore-platform-reqs - composer install --ignore-platform-reqs
- composer run php-cs:check - composer run php-cs:check
- vendor/bin/phpunit # - vendor/bin/phpunit
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
use HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel; use HHIT\ConfigGenerator\Command\GenerateConfigsCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { 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; 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 = [ ...@@ -19,9 +18,9 @@ $candidates = [
]; ];
$autoloaderPath = null; $autoloaderPath = null;
$pojectDir = null; $projectDir = null;
foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) { foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) {
if (file_exists($autoloaderPathCandidate) && file_exists($projectDirCandidate . '/.env')) { if (file_exists($autoloaderPathCandidate)) {
$autoloaderPath = $autoloaderPathCandidate; $autoloaderPath = $autoloaderPathCandidate;
$projectDir = $projectDirCandidate; $projectDir = $projectDirCandidate;
break; break;
...@@ -30,51 +29,16 @@ foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) { ...@@ -30,51 +29,16 @@ foreach ($candidates as $autoloaderPathCandidate => $projectDirCandidate) {
if (null === $autoloaderPath) { if (null === $autoloaderPath) {
throw new RuntimeException('Unable to locate autoload.php file.'); 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; require_once $autoloaderPath;
unset($candidates, $autoloaderPathCandidate, $projectDirCandidate); unset($candidates, $autoloaderPathCandidate, $pojectDirCandidate);
if (!class_exists(Application::class)) { $application = new Application('Configuration Generator');
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.'); $application->add(new GenerateConfigsCommand($projectDir));
}
$input = new ArgvInput(); $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); putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
} }
if ($input->hasParameterOption('--no-debug', true)) { $output = new ConsoleOutput();
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); $application->run($input, $output);
}
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);
{ {
"name": "hhit/config-generator-bundle", "name": "hhit/config-generator",
"type": "contao-bundle", "type": "library",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{"name": "Hendrik Heneke", "email": "heneke@gmail.com"} {"name": "Hendrik Heneke", "email": "heneke@gmail.com"}
...@@ -8,26 +8,21 @@ ...@@ -8,26 +8,21 @@
"minimum-stability": "dev", "minimum-stability": "dev",
"prefer-stable": true, "prefer-stable": true,
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.4",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-json": "*", "ext-json": "*",
"contao/core-bundle": "4.*",
"paragonie/sodium_compat": "^1.14", "paragonie/sodium_compat": "^1.14",
"symfony/framework-bundle": "4.4.*", "symfony/framework-bundle": "4.4.* | 5.2.*",
"symfony/console": "4.4.*", "symfony/console": "4.4.* | 5.2.*",
"symfony/dotenv": "4.4.*", "symfony/dotenv": "4.4.* | 5.2.*",
"symfony/yaml": "4.4.*", "symfony/yaml": "4.4.* | 5.2.*",
"zordius/lightncandy": "^1.2" "zordius/lightncandy": "^1.2"
}, },
"require-dev": { "require-dev": {
"contao/manager-plugin": "^2.0",
"friendsofphp/php-cs-fixer": "^2.16", "friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^9.5" "phpunit/phpunit": "^9.5"
}, },
"conflict": {
"contao/manager-plugin": "<2.0 || >=3.0"
},
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,
"preferred-install": { "preferred-install": {
...@@ -37,25 +32,19 @@ ...@@ -37,25 +32,19 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"HHIT\\ConfigGeneratorBundle\\": "src/" "HHIT\\ConfigGenerator\\": "src/"
} }
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "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": [
"bin/cfgen" "bin/cfgen"
], ],
"scripts": { "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: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" "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 @@ ...@@ -5,9 +5,6 @@
<directory suffix=".php">./src</directory> <directory suffix=".php">./src</directory>
</include> </include>
</coverage> </coverage>
<php>
<env name="KERNEL_CLASS" value="HHIT\ConfigGeneratorBundle\Kernel\StandaloneKernel"/>
</php>
<testsuites> <testsuites>
<testsuite name="Test Suite"> <testsuite name="Test Suite">
<directory>./tests</directory> <directory>./tests</directory>
......
<?php <?php
declare(strict_types=1); 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\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
...@@ -13,32 +13,37 @@ class GenerateConfigsCommand extends Command ...@@ -13,32 +13,37 @@ class GenerateConfigsCommand extends Command
{ {
protected static $defaultName = "cfgen:generate-configs"; protected static $defaultName = "cfgen:generate-configs";
private Generator $generator; private string $projectDir;
public function __construct( public function __construct(string $projectDir, ?string $name = null)
Generator $generator, {
string $name = null $this->projectDir = $projectDir;
) {
parent::__construct($name); parent::__construct($name);
$this->generator = $generator;
} }
protected function configure() protected function configure()
{ {
$this->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'configuration file (default is %kernel.project_dir%/cfgen.json)'); $this->addOption('project', 'p', InputOption::VALUE_OPTIONAL, 'project (dir)', $this->projectDir);
$this->addOption('vault', null, InputOption::VALUE_REQUIRED, 'vault type', 'symfony'); $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'); $this->addOption('overwrite', null, InputOption::VALUE_NONE, 'overwrite existing files');
} }
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
$success = $this->generator->processConfigurations( $env = $input->getOption('env');
$input->getOption('vault'),
$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('overwrite') ? true : false,
$input->getOption('config') ?: null, $input->getOption('config') ?: null,
$output $output
); );
return $success ? 0 : 1; 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