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
|
2005-02-08 19:10:06 +00:00
|
|
|
* @date 2003 - 2005
|
2004-05-10 17:26:03 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-01-04 15:34:39 +00:00
|
|
|
* @version 1.1
|
2004-05-08 12:24:15 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2006-03-30 21:57:28 +00:00
|
|
|
parent::__construct(
|
|
|
|
new RecursiveCachingIterator(
|
|
|
|
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME
|
|
|
|
),
|
|
|
|
CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD
|
|
|
|
),
|
|
|
|
parent::SELF_FIRST
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
?>
|