Permalink
Browse files

Proyx array and ArraObject objects through a new proxy class that sup…

…ports all ArrayObject interfaces.
  • Loading branch information...
1 parent 4144864 commit 88dc190d352f00a831a3925361785a9aba600855 @gauthierm gauthierm committed May 2, 2011
@@ -85,7 +85,7 @@ protected function filterVar($var)
case 'double':
return $this->savant->escape($var);
case 'array':
- return new ObjectProxy\ArrayIterator($var, $this->savant);
+ return new ObjectProxy\ArrayObject(new \ArrayObject($var), $this->savant);
}
return $var;
}
@@ -173,17 +173,15 @@ function __getClass()
*/
public static function factory($object, $savant)
{
+ if ($object instanceof \ArrayObject) {
+ return new ObjectProxy\ArrayObject($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);
- }
return new self($object, $savant);
}
@@ -205,4 +203,4 @@ function count()
{
return count($this->object);
}
-}
+}
@@ -0,0 +1,84 @@
+<?php
+
+/**
+ * PEAR2\Templates\Savant\ObjectProxy\ArrayObject
+ *
+ * PHP version 5
+ *
+ * @category Templates
+ * @package PEAR2_Templates_Savant
+ * @author Brett Bieber <saltybeagle@php.net>
+ * @author Michael Gauthier <mike@silverorange.com>
+ * @copyright 2009 Brett Bieber, 2011 Michael Gauthier
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @version SVN: $Id$
+ * @link http://svn.php.net/repository/pear2/PEAR2_Templates_Savant
+ */
+
+/**
+ * Proxies ArrayObject objects
+ *
+ * Filters on array access or on traversal.
+ *
+ * @category Templates
+ * @package PEAR2_Templates_Savant
+ * @author Brett Bieber <saltybeagle@php.net>
+ * @author Michael Gauthier <mike@silverorange.com>
+ * @copyright 2009 Brett Bieber, 2011 Michael Gauthier
+ * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
+ * @link http://svn.php.net/repository/pear2/PEAR2_Templates_Savant
+ */
+namespace PEAR2\Templates\Savant\ObjectProxy;
+use PEAR2\Templates\Savant\ObjectProxy;
+class ArrayObject
+ extends ArrayAccess
+ implements \ArrayAccess, \Countable, \Serializable, \IteratorAggregate
+{
+ public function getIterator()
+ {
+ return $this->object->getIterator();
+ }
+
+ public function next()
+ {
+ $this->object->next();
+ }
+
+ public function key()
+ {
+ return $this->object->key();
+ }
+
+ public function valid()
+ {
+ return $this->object->valid();
+ }
+
+ public function rewind()
+ {
+ $this->object->rewind();
+ }
+
+ public function current()
+ {
+ return $this->filterVar($this->object->current());
+ }
+
+ public function count()
+ {
+ return count($this->object);
+ }
+
+ public function serialize()
+ {
+ return serialize($this->object);
+ }
+
+ public function unserialize($string)
+ {
+ $object = unserialize($string);
+ if ($object !== false) {
+ $this->object = $object;
+ }
+ }
+}

0 comments on commit 88dc190

Please sign in to comment.