NodeElement.php in Extensible BBCode 8.3
File
src/Parser/Tree/NodeElement.php
View source
<?php
namespace Drupal\xbbcode\Parser\Tree;
use Iterator;
abstract class NodeElement implements NodeElementInterface {
protected $children = [];
protected $output;
public function append(ElementInterface $element) : void {
$this->children[] = $element;
}
public function getChildren() : array {
return $this->children;
}
public function getContent() : string {
return implode('', $this
->getRenderedChildren());
}
public function getRenderedChildren($force_render = TRUE) : array {
if (!$force_render) {
return $this->output ?? [];
}
if ($this->output === NULL) {
$this->output = [];
foreach ($this->children as $child) {
$this->output[] = $child
->render();
}
}
return $this->output;
}
public function getDescendants() : Iterator {
foreach ($this->children as $child) {
(yield $child);
if ($child instanceof NodeElementInterface) {
yield from $child
->getDescendants();
}
}
}
}