|
|
@ -55,7 +55,7 @@ class Engine |
|
|
|
|
|
|
|
$documents = []; |
|
|
|
|
|
|
|
// First, figure out which files to process and load all files. |
|
|
|
// Figure out which files to process and load all files. |
|
|
|
$files = [basename($input_file)]; |
|
|
|
|
|
|
|
for ($i = 0; $i < sizeof($files); $i++) |
|
|
@ -79,72 +79,21 @@ class Engine |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Go through and load all the variables and parameters |
|
|
|
$variables = []; |
|
|
|
$parameters = []; |
|
|
|
for ($i = 0; $i < sizeof($files); $i++) |
|
|
|
{ |
|
|
|
$file_variables = []; |
|
|
|
try |
|
|
|
{ |
|
|
|
$file_variables = $documents[$files[$i]]->getMeta('variables'); |
|
|
|
} |
|
|
|
catch (\Exception $ex) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($file_variables as $k => $v) |
|
|
|
{ |
|
|
|
$variables[$k] = $v; |
|
|
|
} |
|
|
|
|
|
|
|
$file_parameters = []; |
|
|
|
try |
|
|
|
{ |
|
|
|
$file_parameters = $documents[$files[$i]]->getMeta('parameters'); |
|
|
|
} |
|
|
|
catch (\Exception $ex) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($file_parameters as $k => $v) |
|
|
|
{ |
|
|
|
$parameters[$k] = $v; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($variables as $k => $v) |
|
|
|
{ |
|
|
|
if (!$options->hasVariable($k)) |
|
|
|
{ |
|
|
|
$options->setVariable($k, $v); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach ($parameters as $k => $v) |
|
|
|
{ |
|
|
|
if (!$options->hasParameter($k)) |
|
|
|
{ |
|
|
|
$options->setParameter($k, $v); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Now actually process all the documents |
|
|
|
for ($i = 0; $i < sizeof($files); $i++) |
|
|
|
{ |
|
|
|
$this->compileDocument($documents[$files[$i]]); |
|
|
|
} |
|
|
|
$document = $this->compileDocuments($documents, $options); |
|
|
|
|
|
|
|
// Set metadata in output |
|
|
|
$document = $this->getOutputDocument(); |
|
|
|
|
|
|
|
$document->addChildUnderPath('Metadata', new \App\Dom\NodeValue(null, 'Stack', implode(', ', $files))); |
|
|
|
|
|
|
|
// Remove cfnpp block, that doesn't go to CloudFormation |
|
|
|
$cfnpp = $document->getChildByName('cfnpp'); |
|
|
|
if (isset($cfnpp)) |
|
|
|
{ |
|
|
|
$cfnpp->remove(); |
|
|
|
} |
|
|
|
|
|
|
|
// Serialize and return |
|
|
|
// TODO: We'll want to return parameters/etc later. |
|
|
|
return $this->serialize->serialize($document); |
|
|
|
} |
|
|
|
|
|
|
@ -193,7 +142,6 @@ class Engine |
|
|
|
public function setInputDocument(\App\Dom\Document $document): Engine |
|
|
|
{ |
|
|
|
$this->document = $document; |
|
|
|
$this->compile->setDocument($document); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
@ -213,13 +161,14 @@ class Engine |
|
|
|
/** |
|
|
|
* Compile a new document, mutating current state. |
|
|
|
* |
|
|
|
* @param string $document_string |
|
|
|
* @param string $document_string |
|
|
|
* @param IOptions $options |
|
|
|
* @return Engine |
|
|
|
*/ |
|
|
|
public function compile(string $document_string): Engine |
|
|
|
public function compile(string $document_string, IOptions $options): Engine |
|
|
|
{ |
|
|
|
$document = $this->unserialize->unserialize($document_string); |
|
|
|
$this->compileDocument($document); |
|
|
|
$this->compileDocument($document, $options); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
@ -227,11 +176,25 @@ 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 |
|
|
|
{ |
|
|
|
$this->document = $this->compile->compile(isset($this->document) ? [$this->document, $document] : [$document], $options); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Compile a set of documents, mutating current state. |
|
|
|
* |
|
|
|
* @param \App\Dom\Document[] $documents |
|
|
|
* @param IOptions $options |
|
|
|
* @return Engine |
|
|
|
*/ |
|
|
|
public function compileDocument(\App\Dom\Document $document): Engine |
|
|
|
public function compileDocuments(array $documents, IOptions $options): Engine |
|
|
|
{ |
|
|
|
$this->compile->compile($document); |
|
|
|
$this->document = $this->compile->compile(isset($this->document) ? array_merge([$this->document], $documents) : $documents, $options); |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
@ -242,7 +205,7 @@ class Engine |
|
|
|
*/ |
|
|
|
public function getOutputDocument(): \App\Dom\Document |
|
|
|
{ |
|
|
|
return $this->compile->getDocument(); |
|
|
|
return $this->document; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|