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.
79 lines
1.7 KiB
79 lines
1.7 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dom;
|
|
|
|
/**
|
|
* Root node of a document.
|
|
*
|
|
* @author Adam Pippin <hello@adampippin.ca>
|
|
*/
|
|
class Document extends Node
|
|
{
|
|
/**
|
|
* The original name of this document, as they will relate to each other
|
|
* via include/stack refs, etc.
|
|
* @var ?string
|
|
*/
|
|
protected $document_name;
|
|
|
|
public function __construct(?string $document_name = null)
|
|
{
|
|
$this->document_name = $document_name;
|
|
$this->children = [];
|
|
}
|
|
|
|
/**
|
|
* Get this document's name.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getDocumentName(): string
|
|
{
|
|
if (!isset($this->document_name))
|
|
{
|
|
throw new \Exception('No document name set');
|
|
}
|
|
return $this->document_name;
|
|
}
|
|
|
|
/**
|
|
* Set this document's name.
|
|
*
|
|
* @param string $document_name
|
|
* @return void
|
|
*/
|
|
public function setDocumentName(string $document_name): void
|
|
{
|
|
$this->document_name = $document_name;
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
return Node::toPhp($node);
|
|
}
|
|
|
|
/**
|
|
* Set a value on the meta `cfnpp` block in the document.
|
|
*
|
|
* @param string $path a dot-separate path to the value to set/replace
|
|
* @param mixed $data the data to set on that node
|
|
* @return void
|
|
*/
|
|
public function setMeta(string $path, $data): void
|
|
{
|
|
$this->setChildByPath('cfnpp.'.$path, Node::fromPhp($data));
|
|
}
|
|
}
|
|
|