definitionReader = $definitionReader; $this->valuesLoaderFactory = $valuesLoaderFactory; $this->validatorFactory = $validatorFactory; } public function processConfigurations( string $vaultType, bool $overwrite, ?string $configurationFile = null, ?OutputInterface $output = null ): bool { $success = []; foreach ($this->definitionReader->read($configurationFile) as $definition) { /** * @var $definition Definition */ $this->writeln($output, "- processing {$definition->getId()}"); try { $valuesLoader = $this->valuesLoaderFactory->create($definition->getValuesFile(), $definition->getValuesEnvFile(), $vaultType); $compiler = new Compiler($definition->getTemplateFile(), $valuesLoader); $content = $compiler->compile(); try { $this->validatorFactory->createValidator($definition->getType())->validate($content); $definition->getDestinationFile()->parent(false); $writer = new FileWriter($definition->getDestinationFile()); $writer->write($compiler->compile(), $overwrite); $this->writeln($output, "-- configuration written to {$definition->getDestinationFile()->asString()}"); $success[] = true; } catch (ValidationException $ve) { $this->writeln($output, "== generated content for {$definition->getId()} is invalid: {$ve->getMessage()}"); throw $ve; } } catch (\Throwable $t) { if (!$t instanceof ValidationException) { $this->writeln($output, "== generating configuration file {$definition->getId()} failed: {$t->getMessage()}"); if ($output && $output->isVerbose()) { $this->writeln($output, $output->getVerbosity()); $this->writeln($output, "{$t->getTraceAsString()}"); } } $success[] = false; } } return empty($success) ? true : !in_array(false, $success); } private function writeln(?OutputInterface $output, $message) { if ($output) { $output->writeln($message); } } }