StackFormation\Blueprint::getParameters PHP Method

getParameters() public method

public getParameters ( $resolvePlaceholders = true )
    public function getParameters($resolvePlaceholders = true)
    {
        $this->applyEnvVars();
        $parameters = [];
        if (!isset($this->blueprintConfig['parameters'])) {
            return [];
        }
        $prefixes = [];
        foreach (array_keys($this->getTemplates()) as $key) {
            if (!is_int($key)) {
                $prefixes[] = $key;
            }
        }
        foreach (array_keys($this->getOptionalTemplates()) as $key) {
            if (!is_int($key)) {
                $prefixes[] = $key;
            }
        }
        foreach ($this->blueprintConfig['parameters'] as $parameterKey => $parameterValue) {
            if (!preg_match('/^[\\*A-Za-z0-9]{1,255}$/', $parameterKey)) {
                throw new \Exception("Invalid parameter key '{$parameterKey}'.");
            }
            if (is_null($parameterValue)) {
                throw new \Exception("Parameter {$parameterKey} is null.");
            }
            if ($resolvePlaceholders) {
                $parameterValue = $this->valueResolver->resolvePlaceholders($parameterValue, $this, 'parameter', $parameterKey);
            }
            if (!is_scalar($parameterValue)) {
                throw new \Exception('Invalid type for value');
            }
            if (strpos($parameterKey, '*') !== false) {
                // resolve the '*' when using multiple templates with prefixes
                if (empty($prefixes)) {
                    throw new \Exception("Found placeholder '*' in parameter key but the templates don't use prefixes");
                }
                foreach ($prefixes as $prefix) {
                    $parameters[] = ['ParameterKey' => str_replace('*', $prefix, $parameterKey), 'ParameterValue' => $parameterValue];
                }
            } else {
                $parameters[] = ['ParameterKey' => $parameterKey, 'ParameterValue' => $parameterValue];
            }
        }
        return $parameters;
    }

Usage Example

Beispiel #1
0
 public function compare()
 {
     if (empty($this->stack)) {
         throw new \InvalidArgumentException('Stack not set');
     }
     if (empty($this->blueprint)) {
         throw new \InvalidArgumentException('Blueprint not set');
     }
     $tmp = [];
     try {
         // parameters
         if ($this->output->isVerbose()) {
             $this->output->writeln($this->stack->getName() . ': Comparing parameters');
         }
         $parametersStack = $this->stack->getParameters();
         $parametersBlueprint = $this->blueprint->getParameters(true);
         $parametersBlueprint = Div::flatten($parametersBlueprint, 'ParameterKey', 'ParameterValue');
         if ($this->parametersAreEqual($parametersStack, $parametersBlueprint)) {
             $tmp['parameters'] = "<fg=green>equal</>";
         } else {
             $tmp['parameters'] = "<fg=red>different</>";
             $tmp['error'] = true;
         }
         // template
         if ($this->output->isVerbose()) {
             $this->output->writeln($this->stack->getName() . ': Comparing template');
         }
         $templateStack = trim($this->stack->getTemplate());
         $templateBlueprint = trim($this->blueprint->getPreprocessedTemplate());
         $templateStack = $this->normalizeJson($templateStack);
         $templateBlueprint = $this->normalizeJson($templateBlueprint);
         if ($templateStack === $templateBlueprint) {
             $tmp['template'] = "<fg=green>equal</>";
         } else {
             $tmp['template'] = "<fg=red>different</>";
             $tmp['error'] = true;
         }
     } catch (CloudFormationException $e) {
         $tmp['parameters'] = 'Stack not found';
         $tmp['template'] = 'Stack not found';
         $tmp['error'] = true;
     } catch (\Exception $e) {
         $tmp['parameters'] = '<fg=red>EXCEPTION: ' . $e->getMessage() . '</>';
         $tmp['template'] = 'EXCEPTION';
         $tmp['error'] = true;
     }
     return $tmp;
 }
All Usage Examples Of StackFormation\Blueprint::getParameters