File indexing completed on 2025-01-19 05:21:04
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Dom 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 */ 0020 0021 /** 0022 * Results for DOM XPath query 0023 * 0024 * @package Zend_Dom 0025 * @subpackage Query 0026 * @uses Iterator 0027 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0028 * @license http://framework.zend.com/license/new-bsd New BSD License 0029 * @version $Id$ 0030 */ 0031 class Zend_Dom_Query_Result implements Iterator,Countable 0032 { 0033 /** 0034 * Number of results 0035 * @var int 0036 */ 0037 protected $_count; 0038 0039 /** 0040 * CSS Selector query 0041 * @var string 0042 */ 0043 protected $_cssQuery; 0044 0045 /** 0046 * @var DOMDocument 0047 */ 0048 protected $_document; 0049 0050 /** 0051 * @var DOMNodeList 0052 */ 0053 protected $_nodeList; 0054 0055 /** 0056 * Current iterator position 0057 * @var int 0058 */ 0059 protected $_position = 0; 0060 0061 /** 0062 * @var DOMXPath 0063 */ 0064 protected $_xpath; 0065 0066 /** 0067 * XPath query 0068 * @var string 0069 */ 0070 protected $_xpathQuery; 0071 0072 /** 0073 * Constructor 0074 * 0075 * @param string $cssQuery 0076 * @param string|array $xpathQuery 0077 * @param DOMDocument $document 0078 * @param DOMNodeList $nodeList 0079 */ 0080 public function __construct($cssQuery, $xpathQuery, DOMDocument $document, DOMNodeList $nodeList) 0081 { 0082 $this->_cssQuery = $cssQuery; 0083 $this->_xpathQuery = $xpathQuery; 0084 $this->_document = $document; 0085 $this->_nodeList = $nodeList; 0086 } 0087 0088 /** 0089 * Retrieve CSS Query 0090 * 0091 * @return string 0092 */ 0093 public function getCssQuery() 0094 { 0095 return $this->_cssQuery; 0096 } 0097 0098 /** 0099 * Retrieve XPath query 0100 * 0101 * @return string 0102 */ 0103 public function getXpathQuery() 0104 { 0105 return $this->_xpathQuery; 0106 } 0107 0108 /** 0109 * Retrieve DOMDocument 0110 * 0111 * @return DOMDocument 0112 */ 0113 public function getDocument() 0114 { 0115 return $this->_document; 0116 } 0117 0118 /** 0119 * Iterator: rewind to first element 0120 * 0121 * @return DOMNode|null 0122 */ 0123 public function rewind() 0124 { 0125 $this->_position = 0; 0126 return $this->_nodeList->item(0); 0127 } 0128 0129 /** 0130 * Iterator: is current position valid? 0131 * 0132 * @return bool 0133 */ 0134 public function valid() 0135 { 0136 if (in_array($this->_position, range(0, $this->_nodeList->length - 1)) && $this->_nodeList->length > 0) { 0137 return true; 0138 } 0139 return false; 0140 } 0141 0142 /** 0143 * Iterator: return current element 0144 * 0145 * @return DOMElement 0146 */ 0147 public function current() 0148 { 0149 return $this->_nodeList->item($this->_position); 0150 } 0151 0152 /** 0153 * Iterator: return key of current element 0154 * 0155 * @return int 0156 */ 0157 public function key() 0158 { 0159 return $this->_position; 0160 } 0161 0162 /** 0163 * Iterator: move to next element 0164 * 0165 * @return DOMNode|null 0166 */ 0167 public function next() 0168 { 0169 ++$this->_position; 0170 return $this->_nodeList->item($this->_position); 0171 } 0172 0173 /** 0174 * Countable: get count 0175 * 0176 * @return int 0177 */ 0178 public function count() 0179 { 0180 return $this->_nodeList->length; 0181 } 0182 }