|
|
@ -16,12 +16,6 @@ use App\Dom\NodeFunction; |
|
|
|
*/ |
|
|
|
class Cfnpp implements ICompile |
|
|
|
{ |
|
|
|
/** |
|
|
|
* Current document state. |
|
|
|
* @var Document |
|
|
|
*/ |
|
|
|
protected $document; |
|
|
|
|
|
|
|
/** |
|
|
|
* Functions that can be called by the document. |
|
|
|
* |
|
|
@ -44,20 +38,6 @@ class Cfnpp implements ICompile |
|
|
|
*/ |
|
|
|
protected $merge_functions; |
|
|
|
|
|
|
|
public function __construct(IOptions $options) |
|
|
|
{ |
|
|
|
if (!($options instanceof CfnppOptions)) |
|
|
|
{ |
|
|
|
throw new \Exception('Cfnpp compiler requires CfnppOptions'); |
|
|
|
} |
|
|
|
|
|
|
|
$this->document = new Document(); |
|
|
|
$this->functions = []; |
|
|
|
|
|
|
|
$cfnpp_functions = new CfnppFunctions($this, $options); |
|
|
|
$cfnpp_functions->register($this); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Register a function that can be called by the document. |
|
|
|
* |
|
|
@ -84,37 +64,37 @@ class Cfnpp implements ICompile |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the current state that new compilations will be applied to. |
|
|
|
* Compile a set of documents and return the result. |
|
|
|
* |
|
|
|
* @param Document $document |
|
|
|
* @param Document[] $documents |
|
|
|
* @param IOptions $options |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function setDocument(Document $document): void |
|
|
|
public function compile(array $documents, IOptions $options): Document |
|
|
|
{ |
|
|
|
$this->document = $document; |
|
|
|
if (!($options instanceof CfnppOptions)) |
|
|
|
{ |
|
|
|
throw new \Exception('Cfnpp compiler requires CfnppOptions'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Get the document representing the current state. |
|
|
|
* |
|
|
|
* @return Document |
|
|
|
*/ |
|
|
|
public function getDocument(): Document |
|
|
|
// Initialize state |
|
|
|
$document = new Document(); |
|
|
|
$this->functions = []; |
|
|
|
$this->merge_functions = []; |
|
|
|
|
|
|
|
// Register built-in functions |
|
|
|
$cfnpp_functions = new CfnppFunctions($this, $options); |
|
|
|
$cfnpp_functions->register($this); |
|
|
|
|
|
|
|
// Process each passed document |
|
|
|
foreach ($documents as $next_document) |
|
|
|
{ |
|
|
|
return $this->document; |
|
|
|
$this->runMergeFunctions($document, $next_document); |
|
|
|
$this->merge($document, $next_document); |
|
|
|
$this->runFunctions($document); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Apply a new document to the current state. |
|
|
|
* |
|
|
|
* @param Document $document |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function compile(Document $document): void |
|
|
|
{ |
|
|
|
$this->runMergeFunctions($this->document, $document); |
|
|
|
$this->merge($this->document, $document); |
|
|
|
$this->runFunctions($this->document); |
|
|
|
return $document; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|