From b628fc219aaf7961777389201d097061c01f23e1 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sat, 2 Feb 2008 23:09:38 +0000 Subject: - MFH Synch directory changes [DOC] # Class FilesystemIterator was introduced to have a better DirectoryIterator # without having to change DirectoryIterator or RecursiveDirectoryIterator. # On top of FilterIterator the new GlobIterator was introduced. This one allows # to implement Countable(). But a glob stream flattens all structure, so it # cannot be derived from RedursiveIterator. With the new structure all children # of FilesystemIterator have nearly the same behavior. Just their capabilities # are a bit different. Check out new inheritance tree on SplFileInfo: # # [marcus@frodo PHP_5_3]$ php ext/spl/examples/class_tree.php SplFileInfo # make: `sapi/cli/php' is up to date. # SplFileInfo # |-DirectoryIterator (Iterator) # | \-FilesystemIterator # | |-GlobIterator (Countable) # | \-RecursiveDirectoryIterator (RecursiveIterator) # | \-Phar (ArrayAccess, Countable) # |-PharFileInfo # \-SplFileObject (RecursiveIterator, SeekableIterator) # \-SplTempFileObject --- ext/spl/spl_directory.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ext/spl/spl_directory.h') diff --git a/ext/spl/spl_directory.h b/ext/spl/spl_directory.h index 0764920512..aa15742a75 100755 --- a/ext/spl/spl_directory.h +++ b/ext/spl/spl_directory.h @@ -26,7 +26,9 @@ extern PHPAPI zend_class_entry *spl_ce_SplFileInfo; extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator; +extern PHPAPI zend_class_entry *spl_ce_FilesystemIterator; extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator; +extern PHPAPI zend_class_entry *spl_ce_GlobIterator; extern PHPAPI zend_class_entry *spl_ce_SplFileObject; extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject; @@ -50,6 +52,13 @@ typedef struct _spl_other_handler { spl_foreign_clone_t clone; } spl_other_handler; +/* define an overloaded iterator structure */ +typedef struct { + zend_object_iterator intern; + zval *current; + spl_filesystem_object *object; +} spl_filesystem_iterator; + struct _spl_filesystem_object { zend_object std; void *oth; @@ -89,8 +98,19 @@ struct _spl_filesystem_object { char escape; } file; } u; + spl_filesystem_iterator it; }; +static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj) +{ + return &obj->it; +} + +static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it) +{ + return (spl_filesystem_object*)((char*)it - XtOffsetOf(spl_filesystem_object, it)); +} + #define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */ #define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */ #define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000006 /* skip empty lines */ -- cgit v1.2.1