DiDom\Element::setNode PHP Method

setNode() protected method

Sets current \DOMNode instance.
protected setNode ( DOMElement | DOMText | DOMComment $node ) : Element
$node DOMElement | DOMText | DOMComment
return Element
    protected function setNode($node)
    {
        $allowedClasses = ['DOMElement', 'DOMText', 'DOMComment'];
        if (!in_array(get_class($node), $allowedClasses)) {
            throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of DOMElement, DOMText or DOMComment, %s given', __METHOD__, is_object($node) ? get_class($node) : gettype($node)));
        }
        $this->node = $node;
        return $this;
    }

Usage Example

示例#1
0
 /**
  * Sets current \DOMElement instance.
  *
  * @param \DOMElement $node A \DOMElement instance
  *
  * @throws \LogicException If given node is not an anchor
  */
 protected function setNode(\DOMElement $node)
 {
     if ('a' !== $node->nodeName and 'area' !== $node->nodeName and 'link' !== $node->nodeName) {
         throw new \LogicException(sprintf('Unable to navigate from a "%s" tag.', $node->nodeName));
     }
     parent::setNode($node);
 }