You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
2.6 KiB
153 lines
2.6 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Engine\Cfnpp;
|
|
|
|
/**
|
|
* Options for controlling the Cfnpp compilation process.
|
|
*
|
|
* @author Adam Pippin <hello@adampippin.ca>
|
|
*/
|
|
class Options implements \App\Engine\IOptions
|
|
{
|
|
/**
|
|
* Store variables for use in templates.
|
|
*
|
|
* @var array<string,mixed>
|
|
*/
|
|
protected $variables;
|
|
|
|
/**
|
|
* Store the parameters we send to cloudformation.
|
|
*
|
|
* @var array<string,mixed>
|
|
*/
|
|
protected $parameters;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->variables = [];
|
|
$this->parameters = [];
|
|
}
|
|
|
|
/**
|
|
* Set all variables.
|
|
*
|
|
* @param array<string,mixed> $variables
|
|
* @return void
|
|
*/
|
|
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]);
|
|
}
|
|
|
|
/**
|
|
* Set all parameters.
|
|
*
|
|
* @param array<string,mixed> $parameters
|
|
* @return void
|
|
*/
|
|
public function setParameters(array $parameters): void
|
|
{
|
|
$this->parameters = $parameters;
|
|
}
|
|
|
|
/**
|
|
* Retrieve all parameters.
|
|
*
|
|
* @return array<string,mixed>
|
|
*/
|
|
public function getParameters(): array
|
|
{
|
|
return $this->parameters;
|
|
}
|
|
|
|
/**
|
|
* Retrieve the value of a single parameter.
|
|
*
|
|
* @param string $name
|
|
* @throws \Exception if parameter does not exist
|
|
* @return mixed
|
|
*/
|
|
public function getParameter(string $name)
|
|
{
|
|
if (!isset($this->parameters[$name]))
|
|
{
|
|
throw new \Exception('Unset parameter: '.$name);
|
|
}
|
|
return $this->parameters[$name];
|
|
}
|
|
|
|
/**
|
|
* Set a single parameter.
|
|
*
|
|
* @param string $name
|
|
* @param mixed $value
|
|
* @return void
|
|
*/
|
|
public function setParameter(string $name, $value): void
|
|
{
|
|
$this->parameters[$name] = $value;
|
|
}
|
|
|
|
/**
|
|
* Check if a parameter exists.
|
|
*
|
|
* @param string $name
|
|
* @return bool
|
|
*/
|
|
public function hasParameter(string $name): bool
|
|
{
|
|
return isset($this->parameters[$name]);
|
|
}
|
|
}
|
|
|