From 5edfadfc5a9aa535d5c3f0991f3dcff5df7380ba Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 16 Jan 2013 10:29:50 +0000 Subject: Add ArrayAccess and Serializable to Idiorm --- idiorm.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/idiorm.php b/idiorm.php index ac2e033..5b5ebde 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1787,7 +1787,7 @@ * A result set class for working with collections of model instances * @author Simon Holywell */ - class IdiormResultSet implements Countable, IteratorAggregate { + class IdiormResultSet implements Countable, IteratorAggregate, ArrayAccess, Serializable { /** * The current result set as an array * @var array @@ -1843,6 +1843,58 @@ return new ArrayIterator($this->_results); } + /** + * ArrayAccess + * @param int|string $offset + * @return bool + */ + public function offsetExists($offset) { + return isset($this->_results[$offset]); + } + + /** + * ArrayAccess + * @param int|string $offset + * @return mixed + */ + public function offsetGet($offset) { + return $this->_results[$offset]; + } + + /** + * ArrayAccess + * @param int|string $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) { + $this->_results[$offset] = $value; + } + + /** + * ArrayAccess + * @param int|string $offset + */ + public function offsetUnset($offset) { + unset($this->_results[$offset]); + } + + /** + * Serializable + * @return string + */ + public function serialize() { + return serialize($this->_results); + } + + /** + * Serializable + * @param string $serialized + * @return array + */ + public function unserialize($serialized) { + return unserialize($serialized); + } + /** * Call a method on all models in a result set. This allows for method * chaining such as setting a property on all models in a result set or -- cgit v1.2.3