Skip to content

Commit e537b79

Browse files
committed
- MFH Added RecursiveTreeIterator
1 parent f4c3f18 commit e537b79

13 files changed

+881
-33
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ PHP NEWS
117117
. Added new parameter $prepend to spl_autoload_register(). (Etienne)
118118
. Added FixedArray. (Etienne, Tony)
119119
. Added delaying exceptions in SPL's autoload mechanism. (Marcus)
120+
. Added RecursiveTreeIterator. (Arnaud, Marcus)
120121

121122
- Improved Zend Engine:
122123
. Added "compact" handler for Zend MM storage. (Dmitry)

ext/spl/examples/recursivetreeiterator.inc renamed to ext/spl/internal/recursivetreeiterator.inc

+30-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
*/
1111

1212

13-
/** @ingroup Examples
13+
/** @ingroup SPL
1414
* @brief RecursiveIteratorIterator to generate ASCII graphic trees for the
1515
* entries in a RecursiveIterator
1616
* @author Marcus Boerger, Johannes Schlueter
17-
* @version 1.0
17+
* @version 1.1
18+
* @since PHP 5.3
1819
*/
1920
class RecursiveTreeIterator extends RecursiveIteratorIterator
2021
{
@@ -35,16 +36,34 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator
3536
$this->rit_flags = $rit_flags;
3637
}
3738

38-
/** Prefix strings used in getPrefix()
39-
*
40-
* 0: prefix used to start elements
41-
* 1: prefix used if $level < depth and hasNext($level) == true
42-
* 2: prefix used if $level < depth and hasNext($level) == false
43-
* 3: prefix used if $level == depth and hasNext($level) == true
44-
* 4: prefix used if $level == depth and hasNext($level) == false
45-
* 5: prefix used right in front of the current element
39+
private $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>'');
40+
41+
/** Prefix used to start elements. */
42+
const PREFIX_LEFT = 0;
43+
/** Prefix used if $level < depth and hasNext($level) == true. */
44+
const PREFIX_MID_HAS_NEXT = 1;
45+
/** Prefix used if $level < depth and hasNext($level) == false. */
46+
const PREFIX_MID_LAST = 2;
47+
/** Prefix used if $level == depth and hasNext($level) == true. */
48+
const PREFIX_END_HAS_NEXT = 3;
49+
/** Prefix used if $level == depth and hasNext($level) == false. */
50+
const PREFIX_END_LAST = 4;
51+
/** Prefix used right in front of the current element. */
52+
const PREFIX_RIGHT = 5;
53+
54+
/**
55+
* Set prefix part as used in getPrefix() and stored in $prefix.
56+
* @param $part any PREFIX_* const.
57+
* @param $value new prefix string for specified part.
58+
* @throws OutOfRangeException if 0 > $part or $part > 5.
4659
*/
47-
public $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>'');
60+
function setPrefixPart($part, $value)
61+
{
62+
if (0 > $part || $part > 5) {
63+
throw new OutOfRangeException();
64+
}
65+
$this->prefix[$part] = (string)$value;
66+
}
4867

4968
/** @return string to place in front of current element
5069
*/

ext/spl/spl.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* - interface RecursiveIterator extends Iterator
3636
* - interface OuterIterator extends Iterator
3737
* - class RecursiveIteratorIterator implements OuterIterator
38+
* - class RecursiveTreeIterator extends RecursiveIteratorIterator
3839
* - abstract class FilterIterator implements OuterIterator
3940
* - class ParentIterator extends FilterIterator implements RecursiveIterator
4041
* - interface SeekableIterator extends Iterator
@@ -55,7 +56,7 @@
5556
*
5657
* - class SplFileInfo
5758
* - class DirectoryIterator extends SplFileInfo implements Iterator
58-
* - class filesystemIterator extends DirectoryIterator
59+
* - class FilesystemIterator extends DirectoryIterator
5960
* - class RecursiveDirectoryIterator extends FilesystemIterator implements RecursiveIterator
6061
* - class GlobIterator extends FilesystemIterator implements Countable
6162
* - class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator
@@ -1132,7 +1133,7 @@ interface SplObserver
11321133
{
11331134
/** Called from the subject (i.e. when it's value has changed).
11341135
* @param $subject the callee
1135-
:*/
1136+
*/
11361137
function update(SplSubject $subject);
11371138
}
11381139

0 commit comments

Comments
 (0)