Browse Source

Re-add !expr function

Adam Pippin 3 years ago
parent
commit
949a8deb8f
  1. 35
      app/Cfnpp/Functions.php

35
app/Cfnpp/Functions.php

@ -215,23 +215,38 @@ class Functions
* @param NodeFunction $function * @param NodeFunction $function
* @return ?Node * @return ?Node
*/ */
/*
* TODO: Reimplement
public function f_expr(Node $node, NodeFunction $function): ?Node public function f_expr(Node $node, NodeFunction $function): ?Node
{ {
if (!($function instanceof NodeFunctionValue)) if (!($function instanceof NodeFunctionValue))
{ {
throw new \Exception('!if requires scalar argument'); throw new \Exception('!expr requires scalar argument');
} }
$parser = new \App\Cfnpp\Expression\Parser(); $expression = new \App\Cfnpp\Expression\Expression($function->getValue(), $this->options);
$expression = $parser->parse($function->getValue());
$result = $expression->evaluate($this->options->getVariables());
$result = Node::fromPhp($result); if ($expression->isComplete())
$result->setName($node->hasName() ? $node->getName() : null); {
// If we computed a final value/set of values, we can just insert those
// directly.
if ($expression->count() == 1)
{
$solution_node = Node::fromPhp($expression->getValue());
}
else
{
$solution_node = Node::fromPhp($expression->toArray());
}
}
else
{
// Otherwise let's convert it to cfn intrinsics
$solution_node = Node::fromPhp($expression->toCloudformation());
}
return $result; if ($node->hasName())
{
$solution_node->setName($node->getName());
}
return $solution_node;
} }
*/
} }

Loading…
Cancel
Save