You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
950 B
48 lines
950 B
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dom;
|
|
|
|
/**
|
|
* Root node of a document.
|
|
*
|
|
* @author Adam Pippin <hello@adampippin.ca>
|
|
*/
|
|
class Document extends Node
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->children = [];
|
|
}
|
|
|
|
/**
|
|
* Retrieve a value from the meta `cfnpp` block in the document.
|
|
*
|
|
* @param string $path a dot-separated path to the value you want to retrieve
|
|
* @return mixed the value held by the node, or an array of values if the requested node was an array
|
|
*/
|
|
public function getMeta(string $path)
|
|
{
|
|
$node = $this->getChildByPath('cfnpp.'.$path);
|
|
if (!isset($node))
|
|
{
|
|
throw new \Exception('Path not found: '.$path);
|
|
}
|
|
if ($node instanceof NodeValue)
|
|
{
|
|
return $node->getValue();
|
|
}
|
|
elseif ($node->isArray())
|
|
{
|
|
$values = [];
|
|
foreach ($node as $child)
|
|
{
|
|
$values[] = $child->getValue();
|
|
}
|
|
return $values;
|
|
}
|
|
|
|
throw new \Exception('Cannot retrieve meta value: '.$path);
|
|
}
|
|
}
|
|
|