[limb-svn] r6225 - in 3.x/trunk/limb/fs: src tests/cases
svn at limb-project.com
svn at limb-project.com
Wed Aug 8 01:37:20 MSD 2007
Author: pachanga
Date: 2007-08-08 01:37:20 +0400 (Wed, 08 Aug 2007)
New Revision: 6225
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6225
Modified:
3.x/trunk/limb/fs/src/lmbFsRecursiveIterator.class.php
3.x/trunk/limb/fs/tests/cases/lmbFsRecursiveIteratorTest.class.php
Log:
-- lmbFsRecursiveIterator now truly implements Iterator interface
-- lmbFsRecursiveIterator :: current() now returns full file path, not iterator itself
-- tests a bit simplified(need better thought)
Modified: 3.x/trunk/limb/fs/src/lmbFsRecursiveIterator.class.php
===================================================================
--- 3.x/trunk/limb/fs/src/lmbFsRecursiveIterator.class.php 2007-08-07 13:53:21 UTC (rev 6224)
+++ 3.x/trunk/limb/fs/src/lmbFsRecursiveIterator.class.php 2007-08-07 21:37:20 UTC (rev 6225)
@@ -14,14 +14,14 @@
* @package fs
* @version $Id$
*/
-class lmbFsRecursiveIterator
+class lmbFsRecursiveIterator implements Iterator
{
protected $start_dir;
protected $open_dirs = array();
- protected $look_ahead_buffer;
protected $valid;
protected $dir;
protected $item;
+ protected $counter = 0;
function __construct($dir)
{
@@ -31,8 +31,8 @@
function rewind()
{
$this->open_dirs = array();
- $this->look_ahead_buffer = null;
$this->valid = true;
+ $this->counter = 0;
$this->_openDir($this->start_dir);
$this->next();
@@ -91,6 +91,7 @@
$this->dir = $this->_getLastOpenDir();
$this->item = readdir($handle);
+ $this->counter++;
if($this->item !== false)
$this->_openDirIfNeccessary();
@@ -100,9 +101,14 @@
function current()
{
- return $this;//???
+ return $this->getPath();
}
+ function key()
+ {
+ return $this->counter;
+ }
+
function valid()
{
return $this->valid;
Modified: 3.x/trunk/limb/fs/tests/cases/lmbFsRecursiveIteratorTest.class.php
===================================================================
--- 3.x/trunk/limb/fs/tests/cases/lmbFsRecursiveIteratorTest.class.php 2007-08-07 13:53:21 UTC (rev 6224)
+++ 3.x/trunk/limb/fs/tests/cases/lmbFsRecursiveIteratorTest.class.php 2007-08-07 21:37:20 UTC (rev 6225)
@@ -74,51 +74,28 @@
$it = new lmbFsRecursiveIterator($this->dir);
$res = array();
- for($it->rewind(); $it->valid(); $it->next())
- {
- $res[] = $it->getPath();
- }
+ foreach($it as $path)
+ $res[] = $path;
+ asort($res);
$res = array_map(array('lmbFs', 'normalizePath'), $res);
- if(lmbSys :: isWin32())
- {
- $this->assertEqual($res,
- array(lmbFs :: normalizePath($this->dir . '/.'),
- lmbFs :: normalizePath($this->dir . '/..'),
- lmbFs :: normalizePath($this->dir . '/a'),
- lmbFs :: normalizePath($this->dir . '/nested'),
- lmbFs :: normalizePath($this->dir . '/nested/.'),
- lmbFs :: normalizePath($this->dir . '/nested/..'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/.'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/..'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/d'),
- lmbFs :: normalizePath($this->dir . '/nested/b'),
- lmbFs :: normalizePath($this->dir . '/nested/b/.'),
- lmbFs :: normalizePath($this->dir . '/nested/b/..'),
- lmbFs :: normalizePath($this->dir . '/nested/c'),
- ));
- }
- else
- {
- $this->assertEqual($res,
- array(lmbFs :: normalizePath($this->dir . '/.'),
- lmbFs :: normalizePath($this->dir . '/..'),
- lmbFs :: normalizePath($this->dir . '/a'),
- lmbFs :: normalizePath($this->dir . '/nested'),
- lmbFs :: normalizePath($this->dir . '/nested/.'),
- lmbFs :: normalizePath($this->dir . '/nested/..'),
- lmbFs :: normalizePath($this->dir . '/nested/b'),
- lmbFs :: normalizePath($this->dir . '/nested/b/.'),
- lmbFs :: normalizePath($this->dir . '/nested/b/..'),
- lmbFs :: normalizePath($this->dir . '/nested/c'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/.'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/..'),
- lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/d'),
- ));
- }
+ $this->assertEqual($res,
+ array(lmbFs :: normalizePath($this->dir . '/.'),
+ lmbFs :: normalizePath($this->dir . '/..'),
+ lmbFs :: normalizePath($this->dir . '/a'),
+ lmbFs :: normalizePath($this->dir . '/nested'),
+ lmbFs :: normalizePath($this->dir . '/nested/.'),
+ lmbFs :: normalizePath($this->dir . '/nested/..'),
+ lmbFs :: normalizePath($this->dir . '/nested/.sub-nested'),
+ lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/.'),
+ lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/..'),
+ lmbFs :: normalizePath($this->dir . '/nested/.sub-nested/d'),
+ lmbFs :: normalizePath($this->dir . '/nested/b'),
+ lmbFs :: normalizePath($this->dir . '/nested/b/.'),
+ lmbFs :: normalizePath($this->dir . '/nested/b/..'),
+ lmbFs :: normalizePath($this->dir . '/nested/c'),
+ ));
$this->_removeFileSystem();
}
More information about the limb-svn
mailing list