12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- declare(strict_types = 1);
- namespace Fgm\Drupal\Composer;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputDefinition;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- class BuildSettingsCommand extends BaseBuilderCommand {
-
- const BUILD_NAME = 'settings';
-
- protected $eventName;
-
- public function configure() {
- parent::configure();
- $this->eventName = $this->getName();
- $this
- ->setName('build:settings')
- ->setDescription('Step 4: build the *.settings.local.php files.')
- ->setDefinition(
- new InputDefinition([
- new InputArgument(static::ARG_FILE, InputArgument::OPTIONAL, '', static::BUILD_NAME),
- ])
- )
- ->setHelp(
- <<<EOT
- The build:settings command combines shared and per-environment parameters and passes
- them to the settings.local.php.twig template to build the settings/(build|run).settings.local.php files.
- EOT
- );
- }
-
- public function execute(InputInterface $input, OutputInterface $output): int {
- [$wrapper, $params, $msg, $err] = $this->prepare($input, $output, static::BUILD_NAME);
- if ($err != 0) {
- $output->writeln($msg);
- return $err;
- }
- foreach ($params['sites'] as $name => $siteParams) {
- foreach (['build', 'run'] as $stage) {
- $stageSettings = MergeParamsCommand::mergeDeepArray([
- $siteParams['settings']['both'] ?? [],
- $siteParams['settings'][$stage] ?? [],
- ]);
- $stageParams = $siteParams;
- $stageParams['settings'] = $stageSettings;
- $context = [
- 'extra' => array_diff_key($params, ['instance' => 0, 'sites' => 0]),
- 'instance' => $params['instance'],
- 'name' => $name,
- 'stage' => $stage,
- 'site' => $stageParams,
- ];
- $destination = "web/sites/${context['name']}/${context['stage']}.settings.local.php";
- echo "Building $destination\n";
- [$msg, $error] = $this->render($wrapper, $context, $destination);
- if ($error) {
- $output->writeln(sprintf("Failed rendering %s settings for site %s: %s", $stage, $name, $msg));
- return 5;
- }
- }
- }
- return 0;
- }
- }
|