00001 <?php
00002
00019 class RecursiveTreeIterator extends RecursiveIteratorIterator
00020 {
00021 const BYPASS_CURRENT = 0x00000004;
00022 const BYPASS_KEY = 0x00000008;
00023
00024 private $rit_flags;
00025
00032 function __construct(RecursiveIterator $it, $rit_flags = self::BYPASS_KEY, $cit_flags = CachingIterator::CATCH_GET_CHILD, $mode = self::SELF_FIRST)
00033 {
00034 parent::__construct(new RecursiveCachingIterator($it, $cit_flags), $mode, $rit_flags);
00035 $this->rit_flags = $rit_flags;
00036 }
00037
00047 public $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>'');
00048
00051 function getPrefix()
00052 {
00053 $tree = '';
00054 for ($level = 0; $level < $this->getDepth(); $level++)
00055 {
00056 $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2];
00057 }
00058 $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4];
00059
00060 return $this->prefix[0] . $tree . $this->prefix[5];
00061 }
00062
00065 function getEntry()
00066 {
00067 return @(string)parent::current();
00068 }
00069
00072 function getPostfix()
00073 {
00074 return '';
00075 }
00076
00079 function current()
00080 {
00081 if ($this->rit_flags & self::BYPASS_CURRENT)
00082 {
00083 return parent::current();
00084 }
00085 else
00086 {
00087 return $this->getPrefix() . $this->getEntry() . $this->getPostfix();
00088 }
00089 }
00090
00093 function key()
00094 {
00095 if ($this->rit_flags & self::BYPASS_KEY)
00096 {
00097 return parent::key();
00098 }
00099 else
00100 {
00101 return $this->getPrefix() . parent::key() . $this->getPostfix();
00102 }
00103 }
00104
00107 function __call($func, $params)
00108 {
00109 return call_user_func_array(array($this->getSubIterator(), $func), $params);
00110 }
00111 }
00112
00113 ?>