diff options
author | Marcus Boerger <helly@php.net> | 2003-11-09 23:00:50 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-11-09 23:00:50 +0000 |
commit | c3004804412bd9d79a35213be9217df5a43f1ff5 (patch) | |
tree | 53e67d80c8e606126b63667fc4fa735b4a6a04d4 | |
parent | 159c538bcf7cc649410a7e91b11584dcebcf1b55 (diff) | |
download | php-git-c3004804412bd9d79a35213be9217df5a43f1ff5.tar.gz |
Synch exposed functions with c-level iterator functions
-rwxr-xr-x | ext/spl/spl_directory.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 444ac26704..6db4823dd1 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -53,6 +53,8 @@ SPL_METHOD(DirectoryIterator, getPathname); SPL_METHOD(DirectoryIterator, isDot); SPL_METHOD(DirectoryIterator, isDir); +SPL_METHOD(DirectoryTreeIterator, rewind); +SPL_METHOD(DirectoryTreeIterator, next); SPL_METHOD(DirectoryTreeIterator, key); SPL_METHOD(DirectoryTreeIterator, hasChildren); SPL_METHOD(DirectoryTreeIterator, getChildren); @@ -84,6 +86,8 @@ static zend_function_entry spl_ce_dir_class_functions[] = { }; static zend_function_entry spl_ce_dir_tree_class_functions[] = { + SPL_ME(DirectoryTreeIterator, rewind, NULL, ZEND_ACC_PUBLIC) + SPL_ME(DirectoryTreeIterator, next, NULL, ZEND_ACC_PUBLIC) SPL_ME(DirectoryTreeIterator, key, NULL, ZEND_ACC_PUBLIC) SPL_ME(DirectoryTreeIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) SPL_ME(DirectoryTreeIterator, getChildren, NULL, ZEND_ACC_PUBLIC) @@ -400,7 +404,42 @@ SPL_METHOD(DirectoryIterator, isDir) } /* }}} */ -/* {{{ proto bool DirectoryIterator::hasChildren() +/* {{{ proto void DirectoryTreeIterator::rewind() + Rewind dir back to the start */ +SPL_METHOD(DirectoryTreeIterator, rewind) +{ + zval *object = getThis(); + spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); + + intern->index = 0; + if (intern->dirp) { + php_stream_rewinddir(intern->dirp); + } + do { + if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { + intern->entry.d_name[0] = '\0'; + } + } while (!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")); +} +/* }}} */ + +/* {{{ proto void DirectoryTreeIterator::next() + Move to next entry */ +SPL_METHOD(DirectoryTreeIterator, next) +{ + zval *object = getThis(); + spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); + + intern->index++; + do { + if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { + intern->entry.d_name[0] = '\0'; + } + } while (!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")); +} +/* }}} */ + +/* {{{ proto bool DirectoryTreeIterator::hasChildren() Returns whether current entry is a directory and not '.' or '..' */ SPL_METHOD(DirectoryTreeIterator, hasChildren) { @@ -419,7 +458,7 @@ SPL_METHOD(DirectoryTreeIterator, hasChildren) } /* }}} */ -/* {{{ proto DirectoryIterator DirectoryIterator::getChildren() +/* {{{ proto DirectoryTreeIterator DirectoryIterator::getChildren() Returns an iterator fo rthe current entry if it is a directory */ SPL_METHOD(DirectoryTreeIterator, getChildren) { |