From: Marcus Boerger Date: Wed, 16 Jul 2003 20:17:34 +0000 (+0000) Subject: Update examples X-Git-Tag: BEFORE_ARG_INFO~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1131d43b0bbf52548e5298bf8b444cef0556954c;p=php Update examples --- diff --git a/ext/spl/examples/tree.php b/ext/spl/examples/tree.php index 88056e3993..d5f54c3354 100755 --- a/ext/spl/examples/tree.php +++ b/ext/spl/examples/tree.php @@ -9,81 +9,7 @@ * (c) Marcus Boerger */ -class sub_dir implements spl_sequence -{ - protected $adir = array(); - protected $cnt = 0; - protected $path = ""; - protected $curr = ""; - protected $nodots = true; - - function __construct($path, $nodots = true) { - $this->cnt = 0; - $this->path = $path; - } - - function rewind() { - while($this->cnt) { - unset($this->adir[$this->cnt--]); - } - $dir = new spl_dir($this->path); - $dir->path = ""; - $this->adir[1] = $dir; - $this->cnt = 1; - if ($this->nodots) { - while ($this->has_more()) { - $ent = $this->current(); - if ($ent != '.' && $ent != '..') { - break; - } - $this->next(); - } - } - } - - function next() { - if ($this->cnt) { - $dir = $this->adir[$this->cnt]; - $ent = $dir->current(); - $path = $dir->get_path().'/'.$ent; - if ($ent != '.' && $ent != '..' && is_dir($path)) { - $new = new spl_dir($path); - $new->path = $dir->path.$ent.'/'; - $new->cnt = $this->cnt++; - $this->adir[$this->cnt] = $new; - if ($this->nodots) { - while ($new->has_more()) { - $ent = $new->current(); - if ($ent != '.' && $ent != '..') { - break; - } - $new->next(); - } - } - } - $dir->next(); - } - } - - function has_more() { - while ($this->cnt) { - $dir = $this->adir[$this->cnt]; - if ($dir->has_more()) { - return true; - } - unset($this->adir[$this->cnt--]); - } - return false; - } - - function current() { - if ($this->cnt) { - $dir = $this->adir[$this->cnt]; - return $dir->path . $dir->current(); - } - throw new exception("No more elements available"); - } -} +require_once("sub_dir.inc"); foreach(new sub_dir($argv[1]) as $f) { echo "$f\n";