Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Core_View_Type_Array implements ArrayAccess, Countable, IteratorAggregate {
- /* ... */
- protected $iterator = null;
- /* ... */
- public function getIterator($isNew = true) {
- if ($isNew || is_null($this->iterator)) {
- $this->iterator = new Core_View_Type_Array_Iterator(clone $this);
- }
- return $this->iterator;
- }
- /* ... */
- }
- class Core_View_Type_Array_Iterator implements Iterator {
- protected $array;
- protected $keys;
- protected $current;
- protected $length;
- public function __construct(ArrayAccess $array) {
- $this->array = $array;
- $this->keys = $this->array->keys();
- $this->length = $this->array->count();
- $this->rewind();
- }
- public function current() {
- return $this->array->offsetGet($this->keys[$this->current]);
- }
- public function key() {
- return $this->keys[$this->current];
- }
- public function next() {
- $this->current++;
- }
- public function rewind() {
- $this->current = 0;
- }
- public function valid() {
- return $this->current < $this->length;
- }
- public function isFirst() {
- return $this->current == 0;
- }
- public function isLast() {
- return $this->current + 1 == $this->length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment