Browse Source

Write list of yaml files processed to Metadata section of output (poc)

master
Adam Pippin 3 years ago
parent
commit
460168401e
  1. 44
      app/Dom/Node.php
  2. 8
      app/Engine/Engine.php

44
app/Dom/Node.php

@ -198,6 +198,50 @@ class Node implements \ArrayAccess, \Iterator
return $current;
}
/**
* Set a child of this node by a dot-separate path.
*
* Each element of the path can either be a node name or a numeric
* index representing the offset into an array
*
* @todo will explode if you try to write using a numeric index to an array
* element that doesn't exist
* @param string $path
* @param Node $node
*/
public function addChildUnderPath(string $path, Node $node): void
{
$path = explode('.', $path);
$current = $this;
while (sizeof($path))
{
$next = array_shift($path);
if (is_numeric($next))
{
$current = $current[$next];
}
else
{
$next_node = $current->getChildByName($next);
if (!isset($next_node))
{
$next_node = new Node($current, $next);
$current->addChild($next_node);
$current = $next_node;
}
}
if (!isset($current))
{
return;
}
}
$current->addChild($node);
}
/**
* Add a node to this node's children.
*

8
app/Engine/Engine.php

@ -76,11 +76,15 @@ class Engine
continue;
}
}
echo '=> '.$files[$i].PHP_EOL;
$this->compileDocument($document, $options);
}
return $this->getOutput();
// Set metadata in output
$document = $this->getOutputDocument();
$document->addChildUnderPath('Metadata', new \App\Dom\NodeValue(null, 'Stack', implode(', ', $files)));
return $this->serialize->serialize($document);
}
/**

Loading…
Cancel
Save