|
|
@ -5,6 +5,8 @@ declare(strict_types=1); |
|
|
|
namespace App\Engine; |
|
|
|
|
|
|
|
use App\Dom\Document; |
|
|
|
use App\Dom\Node; |
|
|
|
use App\Dom\NodeValue; |
|
|
|
|
|
|
|
class Cfnpp implements ICompile |
|
|
|
{ |
|
|
@ -18,7 +20,60 @@ class Cfnpp implements ICompile |
|
|
|
|
|
|
|
public function compile(Document $document, IOptions $options): void |
|
|
|
{ |
|
|
|
// noop |
|
|
|
$this->compileNodes($this->document, $document); |
|
|
|
} |
|
|
|
|
|
|
|
protected function compileNodes(Node $original, Node $target): void |
|
|
|
{ |
|
|
|
var_dump(get_class($original), get_class($target)); |
|
|
|
if ($target instanceof NodeValue) |
|
|
|
{ |
|
|
|
if ($original instanceof NodeValue) |
|
|
|
{ |
|
|
|
$original->setValue($target->getValue()); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$parent = $original->getParent(); |
|
|
|
$parent->removeChild($original); |
|
|
|
$parent->addChild($target); |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: Add nodefunctions |
|
|
|
elseif ($target instanceof Node) |
|
|
|
{ |
|
|
|
// if they're both maps, add/overwrite by name |
|
|
|
if ($target->isMap() && $original->isMap()) |
|
|
|
{ |
|
|
|
foreach ($target as $target_child) |
|
|
|
{ |
|
|
|
$orig_child = $original->getChildByName($target_child->getName()); |
|
|
|
if (!isset($orig_child)) |
|
|
|
{ |
|
|
|
$original->addChild($target_child); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$this->compileNodes($orig_child, $target_child); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// if they're both arrays, append |
|
|
|
elseif ($target->isArray() && $original->isArray()) |
|
|
|
{ |
|
|
|
foreach ($target as $child) |
|
|
|
{ |
|
|
|
$original->addChild($child); |
|
|
|
} |
|
|
|
} |
|
|
|
// if there's a mismatch, replace |
|
|
|
else |
|
|
|
{ |
|
|
|
$parent = $original->getParent(); |
|
|
|
$parent->removeChild($original); |
|
|
|
$parent->addChild($target); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function getDocument(): Document |
|
|
|