/** * @param string $snippet The snippet identifier * @param string $tenant The tenant ID * @param array $variables optional variables * @return string */ public function render($snippet = null, $tenant = null, array $variables = []) { if ($snippet === null) { $snippet = $this->renderChildren(); } try { $renderedSnippet = $this->snippetService->render($snippet, $tenant, $variables); } catch (\Exception $e) { $renderedSnippet = $e->getMessage(); throw $e; } return $renderedSnippet; }
/** * Previews a rendered snippet * * @param string $snippet the Snippet ID * @param string $tenant the Tenant ID * @return void */ public function renderCommand($snippet, $tenant) { try { $snippetDefinition = $this->snippetService->getSnippetDefinition($snippet); } catch (\InvalidArgumentException $exception) { $this->outputLine('<error>%s</error>', [$exception->getMessage()]); $this->quit(1); return; } $variables = []; foreach ($snippetDefinition->getVariableDefinitions() as $variableName => $definition) { if (!$definition->isRequired()) { continue; } $variableValue = $this->output->ask('Value of "' . $variableName . '":', $definition->hasDefaultValue() ? $definition->getDefaultValue() : null); $variables[$variableName] = $definition->convert($variableValue); } $this->outputLine($this->snippetService->render($snippet, $tenant, $variables)); }