| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | <?phpdeclare(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;/** * Build the build- and run-time settings for all sites in the multisite. * * @package Fgm\Drupal\Composer */class BuildSettingsCommand extends BaseBuilderCommand {  /**   * Machine name of current building process.   */  const BUILD_NAME = 'settings';  /**   * The event triggering this command.   *   * @var string   */  protected $eventName;  /**   * Configures the current command.   */  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(        <<<EOTThe build:settings command combines shared and per-environment parameters and passesthem to the settings.local.php.twig template to build the settings/(build|run).settings.local.php files.EOT      );  }  /**   * Executes the current command.   *   * {@inheritDoc}   */  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;  }}
 |