Skip to content

Commit b67ca45

Browse files
committed
- Update docu
1 parent 208a97a commit b67ca45

9 files changed

+237
-11
lines changed

ext/spl/internal/cachingiterator.inc

+42
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
<?php
22

3+
/** @file cachingiterator.inc
4+
* @ingroup Internal
5+
* @brief class CachingIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
312
define('CIT_CALL_TOSTRING', 1);
413
define('CIT_CATCH_GET_CHILD', 2);
514

15+
/**
16+
* @brief Cached Iteration over another Iterator
17+
* @author Marcus Boerger
18+
* @version 1.1
19+
*
20+
*/
621
class CachingIterator implements OuterIterator
722
{
823
protected $it;
@@ -11,19 +26,29 @@ class CachingIterator implements OuterIterator
1126
protected $valid;
1227
protected $strValue;
1328

29+
/** Construct from another iterator
30+
*
31+
* @param it Iterator to cache
32+
* @param flags Bitmask:
33+
* - CIT_CALL_TOSTRING (whether to call __toString() for every element)
34+
*/
1435
function __construct(Iterator $it, $flags = CIT_CALL_TOSTRING)
1536
{
1637
$this->it = $it;
1738
$this->flags = $flags & (CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD);
1839
$this->next();
1940
}
2041

42+
/** Rewind the Iterator
43+
*/
2144
function rewind()
2245
{
2346
$this->it->rewind();
2447
$this->next();
2548
}
2649

50+
/** Forward to the next element
51+
*/
2752
function next()
2853
{
2954
if ($this->valid = $this->it->valid()) {
@@ -44,31 +69,45 @@ class CachingIterator implements OuterIterator
4469
$this->it->next();
4570
}
4671

72+
/** @return whether teh iterator is valid
73+
*/
4774
function valid()
4875
{
4976
return $this->valid;
5077
}
5178

79+
/** @return whether there is one more element
80+
*/
5281
function hasNext()
5382
{
5483
return $this->it->valid();
5584
}
5685

86+
/** @return the current element
87+
*/
5788
function current()
5889
{
5990
return $this->current;
6091
}
6192

93+
/** @return the current key
94+
*/
6295
function key()
6396
{
6497
return $this->key;
6598
}
6699

100+
/** Aggregate the inner iterator
101+
*/
67102
function __call($func, $params)
68103
{
69104
return call_user_func_array(array($this->it, $func), $params);
70105
}
71106

107+
/** @return the string represenatation that was generated for the current
108+
* element
109+
* @throw exception when CIT_CALL_TOSTRING was not specified in constructor
110+
*/
72111
function __toString()
73112
{
74113
if (!$this->flags & CIT_CALL_TOSTRING) {
@@ -77,6 +116,9 @@ class CachingIterator implements OuterIterator
77116
return $this->strValue;
78117
}
79118

119+
/**
120+
* @return The inner iterator
121+
*/
80122
function getInnerIterator()
81123
{
82124
return $this->it;

ext/spl/internal/cachingrecursiveiterator.inc

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
<?php
22

3+
/** @file cachingrecursiveiterator.inc
4+
* @ingroup Internal
5+
* @brief class CachingRecursiveIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
12+
/**
13+
* @brief
14+
* @author Marcus Boerger
15+
* @version 1.1
16+
*/
317
class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
418
{
519
protected $hasChildren;
620
protected $getChildren;
721

22+
/** Construct from another iterator
23+
*
24+
* @param it Iterator to cache
25+
* @param flags Bitmask:
26+
* - CIT_CALL_TOSTRING (whether to call __toString() for every element)
27+
* - CIT_CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)
28+
*/
829
function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING)
930
{
1031
parent::__construct($it, $flags);
1132
}
12-
33+
34+
/** Rewind Iterator
35+
*/
1336
function rewind();
1437
{
1538
$this->hasChildren = false;
1639
$this->getChildren = NULL;
1740
parent::rewind();
1841
}
1942

43+
/** Forward to next element if necessary then an Iterator for the Children
44+
* will be created.
45+
*/
2046
function next()
2147
{
2248
if ($this->hasChildren = $this->it->hasChildren()) {
@@ -39,11 +65,19 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera
3965
parent::next();
4066
}
4167

68+
/** @return whether the current element has children
69+
* @note The check whether the Iterator for the children can be created was
70+
* already executed. Hence when flag CIT_CATCH_GET_CHILD was given in
71+
* constructor this fucntion returns false so that getChildren does
72+
* not try to access those children.
73+
*/
4274
function hasChildren()
4375
{
4476
return $this->hasChildren;
4577
}
4678

79+
/** @return An Iterator for the children
80+
*/
4781
function getChildren()
4882
{
4983
return $this->getChildren;

ext/spl/internal/filteriterator.inc

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
<?php
22

3+
/** @file filteriterator.inc
4+
* @ingroup Internal
5+
* @brief class FilterIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
312
/**
413
* @brief Regular expression filter for string iterators
514
* @author Marcus Boerger
6-
* @version 1.0
15+
* @version 1.1
716
*
817
* Instances of this class act as a filter around iterators. In other words
918
* you can put an iterator into the constructor and the instance will only

ext/spl/internal/limititerator.inc

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
<?php
22

3+
/** @file limititerator.inc
4+
* @ingroup Internal
5+
* @brief class LimitIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
12+
/**
13+
* @brief Limited Iteration over another Iterator
14+
* @author Marcus Boerger
15+
* @version 1.1
16+
*
17+
*/
318
class LimitIterator implements OuterIterator
419
{
520
protected $it;
621
protected $offset;
722
protected $count;
823
private $pos;
924

10-
// count === NULL means all
25+
/** Construct
26+
*
27+
* @param it Iterator to limit
28+
* @param offset Offset to first element
29+
* @param count Maximum number of elements to show or NULL for all
30+
*/
1131
function __construct(Iterator $it, $offset = 0, $count = -1)
1232
{
1333
if ($offset < 0) {
@@ -22,6 +42,11 @@ class LimitIterator implements OuterIterator
2242
$this->pos = 0;
2343
}
2444

45+
/** Seek to specified position
46+
* @param position offset to seek to (relative to beginning not offset
47+
* specified in constructor).
48+
* @throw exception when position is invalid
49+
*/
2550
function seek($position) {
2651
if ($position < $this->offset) {
2752
throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset);
@@ -39,31 +64,44 @@ class LimitIterator implements OuterIterator
3964
}
4065
}
4166

67+
/** Rewind to offset specified in constructor
68+
*/
4269
function rewind()
4370
{
4471
$this->it->rewind();
4572
$this->pos = 0;
4673
$this->seek($this->offset);
4774
}
4875

76+
/** @return whether iterator is valid
77+
*/
4978
function valid() {
5079
return ($this->count == -1 || $this->pos < $this->offset + $this->count)
5180
&& $this->it->valid();
5281
}
5382

83+
/** @return current key
84+
*/
5485
function key() {
5586
return $this->it->key();
5687
}
5788

89+
/** @return current element
90+
*/
5891
function current() {
5992
return $this->it->current();
6093
}
6194

95+
/** Forward to nect element
96+
*/
6297
function next() {
6398
$this->it->next();
6499
$this->pos++;
65100
}
66101

102+
/** @return current position relative to zero (not to offset specified in
103+
* constructor).
104+
*/
67105
function getPosition() {
68106
return $this->pos;
69107
}

ext/spl/internal/outeriterator.inc

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
<?php
22

3-
/** \ingroup SPL
4-
* \brief Interface to access inner iterator of iterator wrappers
3+
/** @file outeriterator.inc
4+
* @ingroup Internal
5+
* @brief class OuterIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
12+
/**
13+
* @brief Interface to access the current inner iteraor of iterator wrappers
14+
* @author Marcus Boerger
15+
* @version 1.0
516
*/
617
interface OuterIterator extends Iterator
718
{
8-
/** \return inner iterator
19+
/** @return inner iterator
920
*/
1021
function getInnerIterator();
1122
}

ext/spl/internal/parentiterator.inc

+27
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
<?php
22

3+
/** @file parentiterator.inc
4+
* @ingroup Internal
5+
* @brief class FilterIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
12+
/**
13+
* @brief Iterator to filter parents
14+
* @author Marcus Boerger
15+
* @version 1.1
16+
*
17+
* This extended FilterIterator allows a recursive iteration using
18+
* RecursiveIteratorIterator that only shows those elements which have
19+
* children.
20+
*/
321
class ParentIterator extends FilterIterator implements RecursiveIterator
422
{
23+
/** @param $it the RecursiveIterator to filter
24+
*/
525
function __construct(RecursiveIterator $it)
626
{
727
parent::__construct($it);
828
}
29+
30+
/** @return whetehr the current element has children
31+
*/
932
function accept()
1033
{
1134
return $this->it->hasChildren();
1235
}
1336

37+
/** @return whether the current element has children
38+
*/
1439
function hasChildren()
1540
{
1641
return $this->it->hasChildren();
1742
}
1843

44+
/** @return the ParentIterator for the current elements children
45+
*/
1946
function getChildren()
2047
{
2148
return new ParentIterator($this->it->getChildren());

ext/spl/internal/recursiveiterator.inc

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
<?php
22

3+
/** @file recursiveiterator.inc
4+
* @ingroup Internal
5+
* @brief class RecursiveIterator
6+
* @author Marcus Boerger
7+
* @date 2003 - 2004
8+
*
9+
* SPL - Standard PHP Library
10+
*/
11+
12+
/**
13+
* @brief Interface for recursive iteration with RecursiveIteratorIterator
14+
* @author Marcus Boerger
15+
* @version 1.0
16+
*/
317
interface RecursiveIterator implements Iterator
418
{
19+
/** @return whether the current element has children
20+
*/
521
function hasChildren();
22+
23+
/** @return the sub iterator for the current element
24+
*/
625
function getChildren();
726
}
827

0 commit comments

Comments
 (0)