Browse Source

Update compiler options to hold variables

master
Adam Pippin 3 years ago
parent
commit
0f6185d9d8
  1. 65
      app/Engine/CfnppOptions.php
  2. 39
      app/Engine/IOptions.php

65
app/Engine/CfnppOptions.php

@ -11,4 +11,69 @@ namespace App\Engine;
*/
class CfnppOptions implements IOptions
{
/**
* Store variables for use in templates.
*
* @var array<string,mixed>
*/
protected $variables;
public function __construct()
{
$this->variables = [];
}
public function setVariables(array $variables): void
{
$this->variables = $variables;
}
/**
* Retrieve all variables.
*
* @return array<string,mixed>
*/
public function getVariables(): array
{
return $this->variables;
}
/**
* Retrieve the value of a single variable.
*
* @param string $name
* @throws Exception if variable does not exist
* @return mixed
*/
public function getVariable(string $name)
{
if (!isset($this->variables[$name]))
{
throw new \Exception('Unset variable: '.$name);
}
return $this->variables[$name];
}
/**
* Set a single variable.
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setVariable(string $name, $value): void
{
$this->variables[$name] = $value;
}
/**
* Check if a variable exists.
*
* @param string $name
* @return bool
*/
public function hasVariable(string $name): bool
{
return isset($this->variables[$name]);
}
}

39
app/Engine/IOptions.php

@ -11,4 +11,43 @@ namespace App\Engine;
*/
interface IOptions
{
/**
* Set variables for use in template.
*
* @param array<string, mixed> $variables
* @return void
*/
public function setVariables(array $variables): void;
/**
* Retrieve all variables set.
*
* @return array<string,mixed>
*/
public function getVariables(): array;
/**
* Retrieve the value of a single variable.
*
* @param string $name
* @return mixed
*/
public function getVariable(string $name);
/**
* Set a single variable.
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setVariable(string $name, $value): void;
/**
* Check if a variable exists.
*
* @param string $name
* @return bool
*/
public function hasVariable(string $name): bool;
}

Loading…
Cancel
Save