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) public function __construct(IOptions $options)
{ {
if (!($options instanceof CfnppOptions))
{
throw new \Exception('Cfnpp compiler requires CfnppOptions');
}
$this->document = new Document(); $this->document = new Document();
$this->functions = []; $this->functions = [];

5
app/Engine/CfnppFunctions.php

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Engine; namespace App\Engine;
use App\Dom\Document;
use App\Dom\Node; use App\Dom\Node;
use App\Dom\NodeValue; use App\Dom\NodeValue;
use App\Dom\NodeFunction; use App\Dom\NodeFunction;
@ -105,6 +104,10 @@ class CfnppFunctions
*/ */
public function f_var(Node $node, NodeFunction $function): ?Node 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()); $value = $this->options->getVariable($function->getValue());
return new NodeValue(null, $node->hasName() ? $node->getName() : null, $value); 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 = []; $this->variables = [];
} }
/**
* Set all variables.
*
* @param array<string,mixed> $variables
* @return void
*/
public function setVariables(array $variables): void public function setVariables(array $variables): void
{ {
$this->variables = $variables; $this->variables = $variables;
@ -41,8 +47,8 @@ class CfnppOptions implements IOptions
/** /**
* Retrieve the value of a single variable. * Retrieve the value of a single variable.
* *
* @param string $name * @param string $name
* @throws Exception if variable does not exist * @throws \Exception if variable does not exist
* @return mixed * @return mixed
*/ */
public function getVariable(string $name) public function getVariable(string $name)

Loading…
Cancel
Save