helly Sat Mar 3 23:07:33 2007 UTC
Modified files:
/php-src/ext/spl spl_directory.c
Log:
- Add DirectoryIterator::count()
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.125&r2=1.126&diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.125
php-src/ext/spl/spl_directory.c:1.126
--- php-src/ext/spl/spl_directory.c:1.125 Sat Mar 3 21:41:56 2007
+++ php-src/ext/spl/spl_directory.c Sat Mar 3 23:07:33 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_directory.c,v 1.125 2007/03/03 21:41:56 helly Exp $ */
+/* $Id: spl_directory.c,v 1.126 2007/03/03 23:07:33 helly Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -189,7 +189,7 @@
intern->path_len = path_len;
intern->u.dir.dirp = php_stream_u_opendir(type, path, path_len,
options, NULL);
- if (php_stream_is(intern->u.dir.dirp, &php_glob_stream_ops)) {
+ if (intern->u.dir.dirp && php_stream_is(intern->u.dir.dirp,
&php_glob_stream_ops)) {
intern->path.s = php_glob_stream_get_path(intern->u.dir.dirp,
1, &intern->path_len);
intern->path_type = IS_STRING;
intern->flags |= SPL_FILE_DIR_USE_GLOB;
@@ -629,6 +629,19 @@
}
/* }}} */
+/* {{{ proto string DirectoryIterator::count() U
+ Return number of entries in directory, works only when USE_GLOB is in
effect */
+SPL_METHOD(DirectoryIterator, count)
+{
+ spl_filesystem_object *intern =
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (intern->flags & SPL_FILE_DIR_USE_GLOB) {
+ RETURN_LONG(php_glob_stream_get_count(intern->u.dir.dirp));
+ }
+ zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable
to determine count unless USE_GLOG flag is in effect");
+}
+/* }}} */
+
/* {{{ proto string SplFileInfo::getPath() U
Return the path */
SPL_METHOD(SplFileInfo, getPath)
@@ -1597,6 +1610,7 @@
SPL_ME(DirectoryIterator, key, NULL, ZEND_ACC_PUBLIC)
SPL_ME(DirectoryIterator, current, NULL, ZEND_ACC_PUBLIC)
SPL_ME(DirectoryIterator, next, NULL, ZEND_ACC_PUBLIC)
+ SPL_ME(DirectoryIterator, count, NULL, ZEND_ACC_PUBLIC)
SPL_MA(DirectoryIterator, __toString, DirectoryIterator, getFilename,
NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php