Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Dom / NodeList.php
blob51a54abd692a2cfa8644f24e4056913758dbb551
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Dom;
12 use ArrayAccess;
13 use Countable;
14 use DOMDocument;
15 use DOMNodeList;
16 use DOMNode;
17 use Iterator;
19 /**
20 * Nodelist for DOM XPath query
22 class NodeList implements Iterator, Countable, ArrayAccess
24 /**
25 * CSS Selector query
26 * @var string
28 protected $cssQuery;
30 /**
31 * @var DOMDocument
33 protected $document;
35 /**
36 * @var DOMNodeList
38 protected $nodeList;
40 /**
41 * Current iterator position
42 * @var int
44 protected $position = 0;
46 /**
47 * XPath query
48 * @var string
50 protected $xpathQuery;
52 /**
53 * Constructor
55 * @param string $cssQuery
56 * @param string|array $xpathQuery
57 * @param DOMDocument $document
58 * @param DOMNodeList $nodeList
60 public function __construct($cssQuery, $xpathQuery, DOMDocument $document, DOMNodeList $nodeList)
62 $this->cssQuery = $cssQuery;
63 $this->xpathQuery = $xpathQuery;
64 $this->document = $document;
65 $this->nodeList = $nodeList;
68 /**
69 * Retrieve CSS Query
71 * @return string
73 public function getCssQuery()
75 return $this->cssQuery;
78 /**
79 * Retrieve XPath query
81 * @return string
83 public function getXpathQuery()
85 return $this->xpathQuery;
88 /**
89 * Retrieve DOMDocument
91 * @return DOMDocument
93 public function getDocument()
95 return $this->document;
98 /**
99 * Iterator: rewind to first element
101 * @return DOMNode
103 public function rewind()
105 $this->position = 0;
107 return $this->nodeList->item(0);
111 * Iterator: is current position valid?
113 * @return bool
115 public function valid()
117 if (in_array($this->position, range(0, $this->nodeList->length - 1)) && $this->nodeList->length > 0) {
118 return true;
121 return false;
125 * Iterator: return current element
127 * @return DOMNode
129 public function current()
131 return $this->nodeList->item($this->position);
135 * Iterator: return key of current element
137 * @return int
139 public function key()
141 return $this->position;
145 * Iterator: move to next element
147 * @return DOMNode
149 public function next()
151 ++$this->position;
153 return $this->nodeList->item($this->position);
157 * Countable: get count
159 * @return int
161 public function count()
163 return $this->nodeList->length;
167 * ArrayAccess: offset exists
169 * @param int $key
170 * @return bool
172 public function offsetExists($key)
174 if (in_array($key, range(0, $this->nodeList->length - 1)) && $this->nodeList->length > 0) {
175 return true;
177 return false;
181 * ArrayAccess: get offset
183 * @param int $key
184 * @return mixed
186 public function offsetGet($key)
188 return $this->nodeList->item($key);
192 * ArrayAccess: set offset
194 * @param mixed $key
195 * @param mixed $value
196 * @throws Exception\BadMethodCallException when attemptingn to write to a read-only item
198 public function offsetSet($key, $value)
200 throw new Exception\BadMethodCallException('Attempting to write to a read-only list');
204 * ArrayAccess: unset offset
206 * @param mixed $key
207 * @throws Exception\BadMethodCallException when attemptingn to unset a read-only item
209 public function offsetUnset($key)
211 throw new Exception\BadMethodCallException('Attempting to unset on a read-only list');