PHP Classes

File: classes/dom/dom-node-iterable.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   PHP Query   classes/dom/dom-node-iterable.php   Download  
File: classes/dom/dom-node-iterable.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Query
Parse and access XML documents as arrays
Author: By
Last change:
Date: 9 years ago
Size: 2,353 bytes
 

Contents

Class file image Download
<?php
/**
 * This file contains the DomNodeIterable class.
 *
 * PHP Version 5.3
 *
 * @category DOM
 * @package Dom
 * @author Gonzalo Chumillas <gonzalo@soloproyectos.com>
 * @license https://raw.github.com/soloproyectos/core/master/LICENSE BSD 2-Clause License
 * @link https://github.com/soloproyectos/core
 */
namespace com\soloproyectos\common\dom;
use \
Iterator;
use \
Countable;

/**
 * DomNodeIterable class.
 *
 * @category DOM
 * @package Dom
 * @author Gonzalo Chumillas <gonzalo@soloproyectos.com>
 * @license https://raw.github.com/soloproyectos/core/master/LICENSE BSD 2-Clause License
 * @link https://github.com/soloproyectos/core
 */
class DomNodeIterable implements Iterator, Countable
{
   
/**
     * Internal DOM elements.
     * @var array of DOMElement
     */
   
protected $elements = array();

   
/**
     * Gets the current node.
     *
     * This function implements Iterator::current.
     *
     * @return DomNode|false
     */
   
public function current()
    {
       
$elem = current($this->elements);
        return
$elem !== false? DomNode::createFromElement($elem): false;
    }
   
   
/**
     * Gets the next node.
     *
     * This function implements Iterator::next.
     *
     * @return DomNode|false
     */
   
public function next()
    {
       
$elem = next($this->elements);
        return
$elem !== false? DomNode::createFromElement($elem): false;
    }
   
   
/**
     * Gets the key of the current node.
     *
     * This function implements Iterator::key.
     *
     * @return DOMElement|null
     */
   
public function key()
    {
        return
key($this->elements);
    }
   
   
/**
     * Sets the internal pointer to the first element.
     *
     * This function implements Iterator::rewind.
     *
     * @return void
     */
   
public function rewind()
    {
       
reset($this->elements);
    }
   
   
/**
     * Is the current node valid?
     *
     * This function implements Iterator::valid.
     *
     * @return boolean
     */
   
public function valid()
    {
        return (
key($this->elements) !== null);
    }
   
   
/**
     * Gets the number of nodes.
     *
     * This function implements Countable::count.
     *
     * @return integer
     */
   
public function count()
    {
        return
count($this->elements);
    }
}