2003-11-18 22:18:38 +00:00
|
|
|
<?php
|
|
|
|
|
2004-05-10 17:26:03 +00:00
|
|
|
/** @file directorytreeiterator.inc
|
|
|
|
* @ingroup Examples
|
|
|
|
* @brief class DirectoryTreeIterator
|
|
|
|
* @author Marcus Boerger
|
|
|
|
* @date 2003 - 2004
|
|
|
|
*
|
|
|
|
* SPL - Standard PHP Library
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @ingroup Examples
|
2004-05-08 12:24:15 +00:00
|
|
|
* @brief DirectoryIterator to generate ASCII graphic directory trees
|
|
|
|
* @author Marcus Boerger
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
2003-11-18 22:18:38 +00:00
|
|
|
class DirectoryTreeIterator extends RecursiveIteratorIterator
|
|
|
|
{
|
2004-05-08 12:24:15 +00:00
|
|
|
/** Construct from a path.
|
|
|
|
* @param $path directory to iterate
|
|
|
|
*/
|
2004-03-16 10:16:52 +00:00
|
|
|
function __construct($path)
|
2003-11-18 22:18:38 +00:00
|
|
|
{
|
2003-12-08 08:31:08 +00:00
|
|
|
parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1);
|
2003-11-18 22:18:38 +00:00
|
|
|
}
|
2004-05-08 12:24:15 +00:00
|
|
|
|
|
|
|
/** @return the current element prefixed with ASCII graphics
|
|
|
|
*/
|
2003-11-18 22:18:38 +00:00
|
|
|
function current()
|
|
|
|
{
|
|
|
|
$tree = '';
|
2003-11-22 20:51:15 +00:00
|
|
|
for ($l=0; $l < $this->getDepth(); $l++) {
|
2003-11-18 22:34:51 +00:00
|
|
|
$tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' ';
|
2003-11-18 22:18:38 +00:00
|
|
|
}
|
|
|
|
return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
|
2003-12-04 20:24:06 +00:00
|
|
|
. $this->getSubIterator($l)->__toString();
|
2003-11-18 22:18:38 +00:00
|
|
|
}
|
2004-05-08 12:24:15 +00:00
|
|
|
|
|
|
|
/** Aggregates the inner iterator
|
|
|
|
*/
|
2003-11-22 20:51:15 +00:00
|
|
|
function __call($func, $params)
|
|
|
|
{
|
|
|
|
return call_user_func_array(array($this->getSubIterator(), $func), $params);
|
|
|
|
}
|
2003-11-18 22:18:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|