diff options
author | Marcus Boerger <helly@php.net> | 2004-09-26 21:21:45 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2004-09-26 21:21:45 +0000 |
commit | 42bc4cd0cac4195e57938b80925987fec6170312 (patch) | |
tree | f9d38afb108bb7aced1bdf97c88babf0c36a39ff /ext/spl/examples | |
parent | 1f08a96f5a839d3f4168fa82ba5a6015b0b83e43 (diff) | |
download | php-git-42bc4cd0cac4195e57938b80925987fec6170312.tar.gz |
Add new examples
Diffstat (limited to 'ext/spl/examples')
-rwxr-xr-x | ext/spl/examples/iteratoriterator.inc | 77 | ||||
-rwxr-xr-x | ext/spl/examples/outeriterator.inc | 13 |
2 files changed, 90 insertions, 0 deletions
diff --git a/ext/spl/examples/iteratoriterator.inc b/ext/spl/examples/iteratoriterator.inc new file mode 100755 index 0000000000..3290fc767c --- /dev/null +++ b/ext/spl/examples/iteratoriterator.inc @@ -0,0 +1,77 @@ +<?php + +/** \ingroup SPL + * \brief Basic Iterator wrapper + */ +class IteratorIterator implements OuterIterator +{ + /** Construct an IteratorIterator from an Iterator or an IteratorAggregate. + * + * Classes that only implement Traversable can be wrapped only after + * converting class IteratorItaerator into c code. + */ + function __construct(Traversable $iterator) + { + if ($iterator instanceof IteratorAggregate) + { + $iterator = $iterator->getIterator(); + } + if ($iterator instanceof Iterator) + { + $this->iterator = $iterator; + } + else + { + throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorItaerator into c code"); + } + } + + /** \return the inner iterator as passed to the constructor + */ + function getInnerIterator() + { + return $this->iterator; + } + + /** \return whetehr the iterator is valid + */ + function valid() + { + return $this->iterator->valid(); + } + + /** \return current key + */ + function key() + { + return $this->iterator->key(); + } + + /** \return current value + */ + function current() + { + return $this->iterator->current(); + } + + /** forward to next element + */ + function next() + { + return $this->iterator->next(); + } + + /** rewind to the first element + */ + function rewind() + { + return $this->iterator->rewind(); + } + + /** The inner iterator must be public becaus ewhen this class will be + * converted to c code it won't no longer be available. + */ + private $iterator; +} + +?>
\ No newline at end of file diff --git a/ext/spl/examples/outeriterator.inc b/ext/spl/examples/outeriterator.inc new file mode 100755 index 0000000000..49923bab45 --- /dev/null +++ b/ext/spl/examples/outeriterator.inc @@ -0,0 +1,13 @@ +<?php + +/** \ingroup SPL + * \brief Interface to access inner iterator of iterator wrappers + */ +interface OuterIterator extends Iterator +{ + /** \return inner iterator + */ + abstract function getInnerIterator(); +} + +?>
\ No newline at end of file |