/** * Set children * * @param NodeInterface $node * @internal param array $children * @return NodeInterface */ public function addChild(NodeInterface $node) { $node->setParentId($this->getId()); if (!in_array($node->getId(), $this->children)) { $this->children[] = $node->getId(); } return $this; }
/** * Make node of type * * @param $class * @param array $match * @param NodeInterface $parent * @param int $offset * @param int $depth * @return NodeInterface */ public function make(NodeInterface $nodeType, array $match = [], NodeInterface $parent = null, $offset = 0, $depth = 0, $id = null) { $node = clone $nodeType; if ($node->incrementDepth()) { $depth++; } $parentId = $parent ? $parent->getId() : null; $node->setId($this->generateId($id)); $node->setParentId($parentId); $node->setMatch($match); $node->setOffset($offset); $node->setDepth($depth); $node->setup(); $node->setItemAlias($node->getItemAliasFromRawAttributes()); $this->addNode($node); $this->extract($node, $parent); return $node; }
/** * Inject content */ public function injectContent(NodeInterface $child, NodeInterface $parent) { if ($child instanceof BlockInterface or !$child->isPhp()) { $source = $child->compile(); } else { $source = $this->php($child->compile()); } if (!($validate = $child->validate())) { $this->getLexicon()->getFoundation()->getNodeFactory()->getCollection()->forget($child->getId()); } $content = preg_replace($this->search($child->getExtractionId()), $source, $parent->getCurrentContent(), self::LIMIT); $parent->setCurrentContent($content); }