A ver, podrías hacer un decorator, algo así:
Código PHP:
Ver originalinterface Renderer
{
public function render();
}
class HTMLTreeDecorator implements Renderer
{
protected $_iterator;
public function __construct(RecursiveIteratorIterator $it)
{
$this->_iterator = $it;
}
public function render()
{
// iterate container
$prevDepth = -1;
$ulClass = 'list';
$html = '';
foreach ($this->_iterator as $file) {
if($this->_iterator->isDot()) continue;
$depth = $this->_iterator->getDepth();
if ($depth > $prevDepth) {
if ($ulClass && $depth == 0) {
$ulClass = ' class="' . $ulClass . '"';
} else {
$ulClass = '';
}
$html .= '<ul' . $ulClass . '>' . PHP_EOL;
} else if ($prevDepth > $depth) {
for ($i = $prevDepth; $i > $depth; $i--) {
$html .= ' </li>' . PHP_EOL;
$html .= '</ul>' . PHP_EOL;
}
// close previous li tag
$html .= ' </li>' . PHP_EOL;
} else {
// close previous li tag
$html .= ' </li>' . PHP_EOL;
}
$html .= ' <li>' . PHP_EOL
. ' ' . $file . PHP_EOL;
// store as previous depth for next iteration
$prevDepth = $depth;
}
if ($html) {
// done iterating container; close open ul/li tags
for ($i = $prevDepth+1; $i > 0; $i--) {
$html .= ' </li>' . PHP_EOL
. '</ul>' . PHP_EOL;
}
$html = rtrim($html, PHP_EOL
); }
return $html;
}
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {}
}
}
y para utilizarlo seria:
Código PHP:
Ver original$path = '/path/to/dir';
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
$decorator = new HTMLTreeDecorator($iterator);
echo $decorator;
Nota: el render es parte de Zend_Navigation :)
Saludos.