Skip to content

Commit 51f85f0

Browse files
committed
0.4.1 - Added ArrayAccess to EntityIterator
1 parent 341a603 commit 51f85f0

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#Changelog
22
All notable changes will be documented in this file
33

4+
## 0.4.1
5+
6+
- [Internal] Added ArrayAccess to EntityIterator
7+
48
## 0.4 - June 11th, 2015
59

610
- [Feature] Added Search API

src/Entity/EntityIterator.php

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use GuzzleHttp\Message\ResponseInterface as Response;
66
use Swader\Diffbot\Abstracts\Entity;
77

8-
class EntityIterator implements \Countable, \Iterator
8+
class EntityIterator implements \Countable, \Iterator, \ArrayAccess
99
{
1010
/** @var array */
1111
protected $data;
@@ -95,4 +95,72 @@ public function __get($name)
9595

9696
return $entity->$name;
9797
}
98+
99+
/**
100+
* (PHP 5 &gt;= 5.0.0)<br/>
101+
* Whether a offset exists
102+
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
103+
* @param mixed $offset <p>
104+
* An offset to check for.
105+
* </p>
106+
* @return boolean true on success or false on failure.
107+
* </p>
108+
* <p>
109+
* The return value will be casted to boolean if non-boolean was returned.
110+
*/
111+
public function offsetExists($offset)
112+
{
113+
return (isset($this->data[$offset]));
114+
}
115+
116+
/**
117+
* (PHP 5 &gt;= 5.0.0)<br/>
118+
* Offset to retrieve
119+
* @link http://php.net/manual/en/arrayaccess.offsetget.php
120+
* @param mixed $offset <p>
121+
* The offset to retrieve.
122+
* </p>
123+
* @return mixed Can return all value types.
124+
*/
125+
public function offsetGet($offset)
126+
{
127+
if ($this->offsetExists($offset)) {
128+
return $this->data[$offset];
129+
}
130+
}
131+
132+
/**
133+
* (PHP 5 &gt;= 5.0.0)<br/>
134+
* Offset to set
135+
* @link http://php.net/manual/en/arrayaccess.offsetset.php
136+
* @param mixed $offset <p>
137+
* The offset to assign the value to.
138+
* </p>
139+
* @param mixed $value <p>
140+
* The value to set.
141+
* </p>
142+
* @return void
143+
*/
144+
public function offsetSet($offset, $value)
145+
{
146+
throw new \BadMethodCallException(
147+
'Resultset is read only'
148+
);
149+
}
150+
151+
/**
152+
* (PHP 5 &gt;= 5.0.0)<br/>
153+
* Offset to unset
154+
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
155+
* @param mixed $offset <p>
156+
* The offset to unset.
157+
* </p>
158+
* @return void
159+
*/
160+
public function offsetUnset($offset)
161+
{
162+
if ($this->offsetExists($offset)) {
163+
unset($this->data[$offset]);
164+
}
165+
}
98166
}

0 commit comments

Comments
 (0)