Gumbo PHP Library API Documentation
Iterator
[
class tree
] [
index
] [
all elements
]
Todo List
Packages:
Buffer
Collection
Composite
Config
Converter
Curl
Date
DB
Debug
Encryption
Error
Factory
Filter
Flyweight
Http
Input
Iterator
List
Load
Lockable
Log
Map
Number
Observer
Output
Query
Record
Router
Session
Setting
Singleton
Template
Timer
Utility
Valid
Source for file Iterator.class.php
Documentation is available at
Iterator.class.php
<?php
/**
* Gumbo Library Framework
*
* LICENSE
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
*
*
@category
Gumbo
*
@package
Iterator
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@version
0.0.1
*/
/**
* Iterator Pattern Interface
*
* The Iterator is an OOP method for looping through a list of data. The
* pattern consists of an Iterator and an IteratorAggregate (defined in PHP5).
* An Aggregate is responsible for creating and returning an Iterator to the
* program. The following code samples demonstrate the variety of ways to
* loop through an Iterator.
*
* <pre>
* $it = new Gumbo_Iterator (array (...));
* $it->rewind ();
* foreach ($it as $key=>$val) {
* ...
* }
* </pre>
*
* <pre>
* $it->rewind ();
* for ($it;$it->valid ();$it->next ()) {
* $key = $it->key ();
* $val = $it->current ();
* ...
* }
* </pre>
*
* <pre>
* $it->rewind ();
* while ($it->valid ()) {
* $key = $it->key ();
* $val = $it->current ();
* ...
* $it->next ();
* }
* </pre>
*
* An IteratorAggregate is responsible for creating an Iterator. This
* is done by defining an implementation to the single IteratorAggregate
* method. An aggregate works well inside a foreach() loop, in that it does
* not require a new variable to hold a reference to the Iterator, it will
* simply use the Aggregate method to retrieve the Iterator. The for(..) and
* while(..) loops require an Iterator variable reference.
*
* <pre>
* class ConcreteAggregate implements IteratorAggregate {
* ...
* public function getIterator () {
* return new Iterator (array (...)); // where array as data
* }
* }
*
* // to loop through an aggregate
* $aggregate = new ConcreteAggregate ();
* foreach ($aggregate as $key=>$val) {
* ...
* }
* </pre>
*
* The additional methods were defined for diagnostic purposes. They don't
* hold much use for an Iterator object, and may be removed. They work well
* if the programmer uses the Iterator directly.
*
*
@category
Gumbo
*
@package
Iterator
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@desc
Iterator Pattern Interface
*
@version
0.0.1
*/
interface
Gumbo_Interface_Iterator
extends
Iterator
{
/** ACCESSOR METHODS **/
/**
* Returns the array of keys in the object
*
@return
array
*/
public
function
getKeys
(
)
;
/**
* Returns the full array list
*
@return
array
*/
public
function
getList
(
)
;
/**
* Returns the current element incremental number
*
@return
int
*/
public
function
getCurrent
(
)
;
/**
* Returns the total number of elements in the Iterator
*
@return
int
*/
public
function
getTotal
(
)
;
}
?>