Permalink
Browse files

We still need ArrayAccess for objects that implement this, but not all

of the functionality of arrays.
  • Loading branch information...
1 parent 8089d98 commit 414486427ba9c18617d5adf028bd415633262b2c @saltybeagle saltybeagle committed Mar 15, 2011
View
5 src/PEAR2/Templates/Savant/ObjectProxy.php
@@ -176,6 +176,11 @@ public static function factory($object, $savant)
if ($object instanceof \Traversable) {
return new ObjectProxy\Traversable($object, $savant);
}
+
+ if ($object instanceof \ArrayAccess) {
+ return new ObjectProxy\ArrayAccess($object, $savant);
+ }
+
if ($object instanceof \ArrayIterator) {
return new ObjectProxy\ArrayIterator($object, $savant);
}
View
25 src/PEAR2/Templates/Savant/ObjectProxy/ArrayAccess.php
@@ -0,0 +1,25 @@
+<?php
+namespace PEAR2\Templates\Savant\ObjectProxy;
+use PEAR2\Templates\Savant\ObjectProxy;
+class ArrayAccess extends ObjectProxy implements \ArrayAccess
+{
+ function offsetExists($offset)
+ {
+ return $this->object->offsetExists($offset);
+ }
+
+ function offsetGet($offset)
+ {
+ return $this->filterVar($this->object->offsetGet($offset));
+ }
+
+ function offsetSet($offset, $value)
+ {
+ $this->object->offsetSet($offset, $value);
+ }
+
+ function offsetUnset($offset)
+ {
+ $this->object->offsetUnset($offset);
+ }
+}
View
22 src/PEAR2/Templates/Savant/ObjectProxy/ArrayIterator.php
@@ -1,7 +1,7 @@
<?php
namespace PEAR2\Templates\Savant\ObjectProxy;
use PEAR2\Templates\Savant\ObjectProxy;
-class ArrayIterator extends ObjectProxy implements \Iterator, \ArrayAccess, \SeekableIterator, \Countable
+class ArrayIterator extends ObjectProxy\ArrayAccess implements \Iterator, \SeekableIterator, \Countable
{
/**
@@ -44,24 +44,4 @@ function seek($offset)
{
return $this->object->seek($offset);
}
-
- function offsetExists($offset)
- {
- return $this->object->offsetExists($offset);
- }
-
- function offsetGet($offset)
- {
- return $this->filterVar($this->object->offsetGet($offset));
- }
-
- function offsetSet($offset, $value)
- {
- $this->object->offsetSet($offset, $value);
- }
-
- function offsetUnset($offset)
- {
- $this->object->offsetUnset($offset);
- }
}

0 comments on commit 4144864

Please sign in to comment.