Browse Source

Code cleanup

master
Adam Pippin 3 years ago
parent
commit
c0b4fd7dd3
  1. 5
      app/Engine/Cfnpp.php
  2. 5
      app/Engine/CfnppFunctions.php
  3. 10
      app/Engine/CfnppOptions.php

5
app/Engine/Cfnpp.php

@ -46,6 +46,11 @@ class Cfnpp implements ICompile
public function __construct(IOptions $options)
{
if (!($options instanceof CfnppOptions))
{
throw new \Exception('Cfnpp compiler requires CfnppOptions');
}
$this->document = new Document();
$this->functions = [];

5
app/Engine/CfnppFunctions.php

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Engine;
use App\Dom\Document;
use App\Dom\Node;
use App\Dom\NodeValue;
use App\Dom\NodeFunction;
@ -105,6 +104,10 @@ class CfnppFunctions
*/
public function f_var(Node $node, NodeFunction $function): ?Node
{
if (!($function instanceof NodeFunctionValue))
{
throw new \Exception('!var requires scalar argument');
}
$value = $this->options->getVariable($function->getValue());
return new NodeValue(null, $node->hasName() ? $node->getName() : null, $value);
}

10
app/Engine/CfnppOptions.php

@ -23,6 +23,12 @@ class CfnppOptions implements IOptions
$this->variables = [];
}
/**
* Set all variables.
*
* @param array<string,mixed> $variables
* @return void
*/
public function setVariables(array $variables): void
{
$this->variables = $variables;
@ -41,8 +47,8 @@ class CfnppOptions implements IOptions
/**
* Retrieve the value of a single variable.
*
* @param string $name
* @throws Exception if variable does not exist
* @param string $name
* @throws \Exception if variable does not exist
* @return mixed
*/
public function getVariable(string $name)

Loading…
Cancel
Save