From b58efb484b81385478db01d20c87d8fdf905a875 Mon Sep 17 00:00:00 2001 From: Stephan Huber Date: Tue, 7 May 2024 17:51:10 +0200 Subject: [PATCH] feat: Expose settings and host-config when executing scaffold from a script --- src/Scaffolder/Callbacks/ScaffoldCallback.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Scaffolder/Callbacks/ScaffoldCallback.php b/src/Scaffolder/Callbacks/ScaffoldCallback.php index 4db2a560..9cf4db8d 100644 --- a/src/Scaffolder/Callbacks/ScaffoldCallback.php +++ b/src/Scaffolder/Callbacks/ScaffoldCallback.php @@ -41,7 +41,7 @@ public function handle(TaskContextInterface $context, ...$arguments) $scaffold_url = $base_path . substr($scaffold_url, 1); } $scaffold_root_folder = array_shift($arguments); - $tokens = Utilities::mergeData($context->get('tokens', []), $this->getTokens($arguments)); + $tokens = Utilities::mergeData($context->get('tokens', []), $this->getTokens($context, $arguments)); $this->scaffold($context, $scaffold_url, $scaffold_root_folder, $tokens); } @@ -73,9 +73,14 @@ public function scaffold( $scaffolder->scaffold($scaffold_url, dirname($scaffold_root_folder), $cloned_context, $tokens, $options); } - private function getTokens(array $arguments):array + private function getTokens(TaskContextInterface $context, array $arguments):array { $result = []; + if ($config = $context->getConfigurationService()) { + $result['settings'] = $config->getAllSettings(); + $shell = $context->getShell(); + $result['host'] = $shell && $shell->getHostConfig() ? $shell->getHostConfig()->asArray() : []; + } foreach ($arguments as $arg) { if (strpos($arg, "=") === false) { throw new \RuntimeException(sprintf("Can't parse argument %s", $arg));