public function compare(dom\node $element) { if ($element->getType() == self::TEXT && $element->getValue() == $this->getValue()) { return self::COMPARE_SUCCESS; } return self::COMPARE_BAD_ELEMENT; }
protected function nodeToInstance(dom\node $node) { if ($node instanceof dom\handler) { $sNamespace = $node->getRoot()->getNamespace(); } else { if ($node instanceof dom\element) { $sNamespace = $node->getNamespace(); } else { $this->throwException(sprintf('Cannot convert %s to instance', $node->asToken())); } } if ($sNamespace == $this->getNamespace()) { $result = $node; } else { $result = $this->createTemplate($node); } return $result; }
/** * Compare two elements and their content, ignore xmlns attributes * Not identical, but relevant to @method isEqualNode() * * @param dom\element $element The element to compare with this one * @param? array $aPath The previous compared element for backtrace debug * * @return integer @const self::COMPARE_SUCCESS, @const self::COMPARE_BAD_ELEMENT, @const self::COMPARE_BAD_CHILD, @const self::COMPARE_BAD_ATTRIBUTE */ public function compare(dom\node $element, $aPath = array()) { $aPath[] = $this->getName(); $this->compareBadNode = $this; if ($element->getType() == self::TEXT || !($this->getName() == $element->getName()) || !($this->getNamespace() == $element->getNamespace())) { $this->compareBadNode = $this; return self::COMPARE_BAD_ELEMENT; } if ($this->readAttribute('ignore', self::COMPARE_NS, false)) { return self::COMPARE_SUCCESS; } $attribute = self::compareAttributes($this, $element); if ($attribute !== true) { $this->compareBadNode = $attribute; return self::COMPARE_BAD_ATTRIBUTE; } if ($this->getChildren()->length != $element->getChildren()->length) { $this->compareBadNode = $this; return self::COMPARE_BAD_CHILD; } else { foreach ($element->getChildren() as $iKey => $child) { if ($selfChild = $this->getChildren()->item($iKey)) { $iResult = $selfChild->compare($child, $aPath); if ($iResult !== self::COMPARE_SUCCESS) { if ($selfChild->getType() == self::ELEMENT) { $this->compareBadNode = $selfChild->compareBadNode; } return self::COMPARE_BAD_CHILD; } } else { $this->compareBadNode = $this; return self::COMPARE_BAD_CHILD; } } } return self::COMPARE_SUCCESS; }
protected function parseChildrenOther(dom\node $node, array &$aResult) { switch ($node->getType()) { case $node::COMMENT: break; case $node::CDATA: $aResult[] = (string) $node; break; default: $this->throwException('Node type not allowed here', array($node->asToken())); } }
public function loadDomElement(dom\node $node) { if ($node instanceof dom\document) { $result = $node->getRoot(); } else { $result = $node; } if (!$result) { $this->throwException('No result node'); } return $result; }
protected function importView(dom\node $source, dom\node $target) { if ($sPath = $source->readx('@extends', array(), false)) { $file = $this->getSourceFile($sPath); $new = $this->importDocument($file->asDocument(array(), \Sylma::MODE_EXECUTE, false), $file); $target->shift($new->getRoot()->getChildren()); $this->importView($new, $target); } }