|
SPL-StandardPHPLibrary
|
00001 <?php 00002 00017 class DirectoryTreeIterator extends RecursiveIteratorIterator 00018 { 00022 function __construct($path) 00023 { 00024 parent::__construct( 00025 new RecursiveCachingIterator( 00026 new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME 00027 ), 00028 CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD 00029 ), 00030 parent::SELF_FIRST 00031 ); 00032 } 00033 00036 function current() 00037 { 00038 $tree = ''; 00039 for ($l=0; $l < $this->getDepth(); $l++) { 00040 $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' '; 00041 } 00042 return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') 00043 . $this->getSubIterator($l)->__toString(); 00044 } 00045 00048 function __call($func, $params) 00049 { 00050 return call_user_func_array(array($this->getSubIterator(), $func), $params); 00051 } 00052 } 00053 00054 ?>
1.7.5.1