helly Tue Nov 18 17:18:39 2003 EDT Added files: /spl/examples cachingiterator.inc cachingrecursiveiterator.inc directorytreeiterator.inc recursiveiterator.inc
Modified files: /spl/examples directorytree.php limititerator.inc searchiterator.inc Log: update directory examples Index: spl/examples/directorytree.php diff -u spl/examples/directorytree.php:1.2 spl/examples/directorytree.php:1.3 --- spl/examples/directorytree.php:1.2 Sun Nov 16 19:56:15 2003 +++ spl/examples/directorytree.php Tue Nov 18 17:18:38 2003 @@ -11,8 +11,8 @@ $length = $argc > 3 ? $argv[3] : NULL; -foreach(new RecursiveIteratorIterator(new DirectoryTreeIterator($argv[1])) as $pathname => $file) { - echo "$pathname\n"; +foreach(new LimitIterator(new DirectoryTreeIterator($argv[1]), @$argv[2], $length) as $pathname => $file) { + echo "$file\n"; } ?> \ No newline at end of file Index: spl/examples/limititerator.inc diff -u spl/examples/limititerator.inc:1.2 spl/examples/limititerator.inc:1.3 --- spl/examples/limititerator.inc:1.2 Tue Nov 11 13:31:50 2003 +++ spl/examples/limititerator.inc Tue Nov 18 17:18:38 2003 @@ -21,7 +21,7 @@ { $this->it->rewind(); $this->index = 0; - if (is_a($this->it, 'SeekableIterator')) { + if ($this->it instanceof SeekableIterator) { $this->index = $this->it->seek($this->offset); } else { while($this->index < $this->offset && $this->it->hasMore()) { Index: spl/examples/searchiterator.inc diff -u spl/examples/searchiterator.inc:1.1 spl/examples/searchiterator.inc:1.2 --- spl/examples/searchiterator.inc:1.1 Sun Nov 9 09:05:36 2003 +++ spl/examples/searchiterator.inc Tue Nov 18 17:18:38 2003 @@ -4,6 +4,11 @@ { private $done = false; + function rewind() { + parent::rewind(); + $this->done = false; + } + function hasMore() { return !$this->done && parent::hasMore(); } Index: spl/examples/cachingiterator.inc +++ spl/examples/cachingiterator.inc <?php class CachingIterator { protected $it; protected $current; protected $key; protected $more; protected $strvalue; function __construct(Iterator $it) { $this->it = $it; } function rewind() { $this->it->rewind(); $this->next(); } function next() { if ($this->more = $this->it->hasMore()) { $this->current = $this->it->current(); $this->key = $this->it->key(); $this->strvalue = (string)$this->current; } else { $this->current = NULL; $this->key = NULL; $this->strvalue = ''; } $this->it->next(); } function hasMore() { return $this->more; } function hasNext() { return $this->it->hasMore(); } function current() { return $this->current; } function key() { return $this->key; } function __call($func, $params) { return call_user_func_array(array($this->it, $func), $params); } function __toString() { return $this->strvalue; } } ?> Index: spl/examples/cachingrecursiveiterator.inc +++ spl/examples/cachingrecursiveiterator.inc <?php class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator { protected $hasChildren; protected $getChildren; function __construct(RecursiveIterator $it) { parent::__construct($it); } function next() { if ($this->hasChildren = $this->it->hasChildren()) { $this->getChildren = new CachingRecursiveIterator($this->it->getChildren()); } else { $this->getChildren = NULL; } parent::next(); } function hasChildren() { return $this->hasChildren; } function getChildren() { return $this->getChildren; } } ?> Index: spl/examples/directorytreeiterator.inc +++ spl/examples/directorytreeiterator.inc <?php class DirectoryTreeIterator extends RecursiveIteratorIterator { function __construct($path) { parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path)), 1); } function current() { $tree = ''; for ($l=0; $l < $this->getLevel(); $l++) { $tree .= $this->getSubIterator($l)->hasMore() ? '| ' : ' '; } return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') . $this->getSubIterator($l); } } ?> Index: spl/examples/recursiveiterator.inc +++ spl/examples/recursiveiterator.inc <?php interface RecursiveIterator implements Iterator { function hasChildren(); function getChildren(); } ?> -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php