cvs: php-src /ext/spl/examples appenditerator.inc findfile.inc findfile.php
| From: | Marcus Boerger | Date: | Sun, 25 Apr 2004 13:06:15 +0000 |
| Subject: | cvs: php-src /ext/spl/examples appenditerator.inc findfile.inc findfile.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-27182@lists.php.net to get a copy of this message | ||
helly Sun Apr 25 09:06:15 2004 EDT
Added files:
/php-src/ext/spl/examples appenditerator.inc
Modified files:
/php-src/ext/spl/examples findfile.inc findfile.php
Log:
Add new iterator example AppendIterator and use it in findfile.php example.
# The initial idea came from a request by Sebastian
http://cvs.php.net/diff.php/php-src/ext/spl/examples/findfile.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/findfile.inc
diff -u php-src/ext/spl/examples/findfile.inc:1.1 php-src/ext/spl/examples/findfile.inc:1.2
--- php-src/ext/spl/examples/findfile.inc:1.1 Sun Jan 25 08:03:24 2004
+++ php-src/ext/spl/examples/findfile.inc Sun Apr 25 09:06:15 2004
@@ -13,7 +13,16 @@
function __construct($path, $file)
{
$this->file = $file;
- parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ $list = split(';', $path);
+ if (count($list) <= 1) {
+ parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ } else {
+ $it = new AppendIterator();
+ foreach($list as $path) {
+ $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ }
+ parent::__construct($it);
+ }
}
function accept()
http://cvs.php.net/diff.php/php-src/ext/spl/examples/findfile.php?r1=1.5&r2=1.6&ty=u
Index: php-src/ext/spl/examples/findfile.php
diff -u php-src/ext/spl/examples/findfile.php:1.5 php-src/ext/spl/examples/findfile.php:1.6
--- php-src/ext/spl/examples/findfile.php:1.5 Sun Jan 25 08:03:24 2004
+++ php-src/ext/spl/examples/findfile.php Sun Apr 25 09:06:15 2004
@@ -4,15 +4,16 @@
*
* Usage: php findfile.php <path> <name>
*
- * <path> Path to search in.
+ * <path> Path to search in. You can specify multiple paths by separating
+ * them with ';'.
* <name> Filename to look for.
*
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
*/
if ($argc < 3) {
echo <<<EOF
-Usage: php findfile.php <file> <name>
+Usage: php findfile.php <path> <name>
Find a specific file by name.
http://cvs.php.net/co.php/php-src/ext/spl/examples/appenditerator.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/appenditerator.inc
+++ php-src/ext/spl/examples/appenditerator.inc
<?php
/**
* @brief Iterator that iterates over several iterators one after the other
* @author Marcus Boerger
* @version 1.0
*
*/
class AppendIterator implements Iterator
{
protected $iterators;
function __construct()
{
$this->iterators = new ArrayIterator();
}
function append(Iterator $it)
{
$this->iterators->append($it);
}
function getInnerIterator()
{
return $this->iterators->current();
}
function rewind()
{
$this->iterators->rewind();
}
function valid()
{
return $this->iterators->valid() && $this->getInnerIterator()->valid();
}
function current()
{
return $this->getInnerIterator()->current();
}
function key()
{
return $this->getInnerIterator()->key();
}
function next()
{
while($this->iterators->valid()) {
$this->getInnerIterator()->next();
if ($this->valid()) {
return;
}
$this->iterators->next();
}
}
}
?>