123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace Gogs\Lib {
- /**
- * Base class for collections. Implements basic
- * functions and typically used to return collections
- * which wont be a part of the "request package"
- *
- * @author Joachim M. Giaever (joachim[]giaever.org)
- */
- class Collection implements ArrayIterator {
- private $objs = array();
- /**
- * Set value(e) to the collection.
- *
- * If the value is an array it will overwrite
- * the whole object-array, aka everything.
- */
- public function set($val, $key = null) {
- if ($key == null && is_array($val))
- $this->objs = $val;
- else if ($key != null)
- $this->objs[$key] = $val;
- else
- array_push($this->objs, $val);
- }
- /**
- * @see ArrayIterator
- */
- public function by_key($idx) {
- return isset($this->objs[$idx]) ? $this->objs[$idx] : false;
- }
- /**
- * @see ArrayIterator
- */
- public function all() {
- return $this->objs;
- }
- /**
- * @see ArrayIterator
- */
- public function len() {
- return count($this->objs);
- }
- /**
- * @see ArrayIterator
- */
- public function next() {
- return next($this->objs);
- }
- /**
- * @see ArrayIterator
- */
- public function prev() {
- return prev($this->objs);
- }
- /**
- * @see ArrayIterator
- */
- public function current() {
- return current($this->objs);
- }
- /**
- * @see ArrayIterator
- */
- public function reset() {
- return reset($this->objs);
- }
- }
- }
|