isNodeList() public static method

Check if $elements is a traversable node list. It returns the $elements or NULL
public static isNodeList ( mixed $elements ) : Traversable | array
$elements mixed
return Traversable | array
Ejemplo n.º 1
0
 /**
  * @param mixed $content
  * @param bool $includeTextNodes
  * @param int $limit
  * @return array|\Traversable null
  */
 private function getNodeList($content, $includeTextNodes = TRUE, $limit = -1)
 {
     if ($callback = Constraints::isCallable($content)) {
         $content = $callback();
     }
     if ($content instanceof \DOMElement) {
         return array($content);
     } elseif ($includeTextNodes && Constraints::isNode($content)) {
         return array($content);
     } elseif (Constraints::isNodeList($content)) {
         return $this->getLimitedArray($content, $limit);
     }
     return NULL;
 }
Ejemplo n.º 2
0
 /**
  * Push new element(s) an the internal element list
  *
  * @param \DOMNode|\Traversable|array|NULL $elements
  * @param boolean $ignoreTextNodes ignore text nodes
  * @throws \OutOfBoundsException
  * @throws \InvalidArgumentException
  * @return $this
  */
 public function push($elements, $ignoreTextNodes = FALSE)
 {
     if (Constraints::isNode($elements, $ignoreTextNodes)) {
         if ($elements->ownerDocument !== $this->_document) {
             throw new \OutOfBoundsException('Node is not a part of this document');
         }
         $this->_nodes[] = $elements;
     } elseif ($nodes = Constraints::isNodeList($elements)) {
         $this->_useDocumentContext = FALSE;
         foreach ($nodes as $index => $node) {
             if ($node->ownerDocument !== $this->_document) {
                 throw new \OutOfBoundsException(sprintf('Node #%d is not a part of this document', $index));
             }
             $this->_nodes[] = $node;
         }
     } elseif (NULL !== $elements) {
         throw new \InvalidArgumentException('Invalid elements variable.');
     }
     return $this;
 }