|
|
@ -52,12 +52,16 @@ class Engine |
|
|
|
{ |
|
|
|
$file_helper = new File([dirname(realpath($input_file))]); |
|
|
|
|
|
|
|
$files = [$input_file]; |
|
|
|
$files = [basename($input_file)]; |
|
|
|
$processed = []; |
|
|
|
|
|
|
|
for ($i = 0; $i < sizeof($files); $i++) |
|
|
|
{ |
|
|
|
// Read the current document |
|
|
|
$document = $this->unserialize->unserialize(file_get_contents($file_helper->resolve($files[$i]))); |
|
|
|
|
|
|
|
// If we haven't already examined this document's list of included templates, |
|
|
|
// then read those and add them to the stack. |
|
|
|
if (!in_array($files[$i], $processed)) |
|
|
|
{ |
|
|
|
$additional_files = []; |
|
|
@ -68,21 +72,30 @@ class Engine |
|
|
|
catch (\Exception $ex) |
|
|
|
{ |
|
|
|
} |
|
|
|
// If the document specified any includes, then push those into our list of templates to process _before_ |
|
|
|
// the existing templates, then walk our loop index back one to reprocess the current index (now one of |
|
|
|
// the inserted files) |
|
|
|
if (sizeof($additional_files)) |
|
|
|
{ |
|
|
|
$processed[] = $files[$i]; |
|
|
|
array_splice($files, $i, 0, $additional_files); |
|
|
|
$i -= sizeof($additional_files); |
|
|
|
--$i; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
$this->compileDocument($document, $options); |
|
|
|
|
|
|
|
$this->compileDocument($document); |
|
|
|
} |
|
|
|
|
|
|
|
// Set metadata in output |
|
|
|
$document = $this->getOutputDocument(); |
|
|
|
|
|
|
|
$document->addChildUnderPath('Metadata', new \App\Dom\NodeValue(null, 'Stack', implode(', ', $files))); |
|
|
|
$cfnpp = $document->getChildByName('cfnpp'); |
|
|
|
if (isset($cfnpp)) |
|
|
|
{ |
|
|
|
$cfnpp->remove(); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->serialize->serialize($document); |
|
|
|
} |
|
|
@ -152,14 +165,13 @@ class Engine |
|
|
|
/** |
|
|
|
* Compile a new document, mutating current state. |
|
|
|
* |
|
|
|
* @param string $document_string |
|
|
|
* @param IOptions $options |
|
|
|
* @param string $document_string |
|
|
|
* @return Engine |
|
|
|
*/ |
|
|
|
public function compile(string $document_string, IOptions $options): Engine |
|
|
|
public function compile(string $document_string): Engine |
|
|
|
{ |
|
|
|
$document = $this->unserialize->unserialize($document_string); |
|
|
|
$this->compileDocument($document, $options); |
|
|
|
$this->compileDocument($document); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
@ -167,12 +179,11 @@ class Engine |
|
|
|
* Compile a new document, mutating current state. |
|
|
|
* |
|
|
|
* @param \App\Dom\Document $document |
|
|
|
* @param IOptions $options |
|
|
|
* @return Engine |
|
|
|
*/ |
|
|
|
public function compileDocument(\App\Dom\Document $document, IOptions $options): Engine |
|
|
|
public function compileDocument(\App\Dom\Document $document): Engine |
|
|
|
{ |
|
|
|
$this->compile->compile($document, $options); |
|
|
|
$this->compile->compile($document); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|