2003-07-16 15:13:23 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2009-03-10 23:40:06 +00:00
| PHP Version 6 |
2003-07-16 15:13:23 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2008-12-31 11:12:40 +00:00
| Copyright ( c ) 1997 - 2009 The PHP Group |
2003-07-16 15:13:23 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2006-01-01 13:10:10 +00:00
| This source file is subject to version 3.01 of the PHP license , |
2003-07-16 15:13:23 +00:00
| that is bundled with this package in the file LICENSE , and is |
| available through the world - wide - web at the following url : |
2006-01-01 13:10:10 +00:00
| http : //www.php.net/license/3_01.txt |
2003-07-16 15:13:23 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Author : Marcus Boerger < helly @ php . net > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
# include "php.h"
# include "php_ini.h"
# include "ext/standard/info.h"
2005-03-07 00:40:57 +00:00
# include "ext/standard/file.h"
# include "ext/standard/php_string.h"
2003-07-16 15:13:23 +00:00
# include "zend_compile.h"
2004-02-12 10:43:27 +00:00
# include "zend_exceptions.h"
2003-11-09 14:05:36 +00:00
# include "zend_interfaces.h"
2003-07-16 15:13:23 +00:00
# include "php_spl.h"
# include "spl_functions.h"
# include "spl_engine.h"
2003-11-09 14:05:36 +00:00
# include "spl_iterators.h"
2003-12-02 07:13:53 +00:00
# include "spl_directory.h"
2005-03-07 00:40:57 +00:00
# include "spl_exceptions.h"
2003-07-16 15:13:23 +00:00
# include "php.h"
# include "fopen_wrappers.h"
2003-11-09 14:05:36 +00:00
# include "ext/standard/basic_functions.h"
# include "ext/standard/php_filestat.h"
2007-03-03 23:41:43 +00:00
2009-03-10 23:27:59 +00:00
# define SPL_HAS_FLAG(flags, test_flag) ((flags & test_flag) ? 1 : 0)
2003-11-09 14:05:36 +00:00
/* declare the class handlers */
2005-10-08 18:57:17 +00:00
static zend_object_handlers spl_filesystem_object_handlers ;
2003-11-09 14:05:36 +00:00
/* decalre the class entry */
2005-10-08 15:55:04 +00:00
PHPAPI zend_class_entry * spl_ce_SplFileInfo ;
2004-11-01 20:57:23 +00:00
PHPAPI zend_class_entry * spl_ce_DirectoryIterator ;
2008-02-02 22:53:05 +00:00
PHPAPI zend_class_entry * spl_ce_FilesystemIterator ;
2004-11-01 20:57:23 +00:00
PHPAPI zend_class_entry * spl_ce_RecursiveDirectoryIterator ;
2008-02-02 22:53:05 +00:00
PHPAPI zend_class_entry * spl_ce_GlobIterator ;
2005-09-15 14:07:39 +00:00
PHPAPI zend_class_entry * spl_ce_SplFileObject ;
2005-10-29 15:15:22 +00:00
PHPAPI zend_class_entry * spl_ce_SplTempFileObject ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
static void spl_filesystem_file_free_line ( spl_filesystem_object * intern TSRMLS_DC ) /* { { { */
{
if ( intern - > u . file . current_line ) {
efree ( intern - > u . file . current_line ) ;
intern - > u . file . current_line = NULL ;
}
if ( intern - > u . file . current_zval ) {
zval_ptr_dtor ( & intern - > u . file . current_zval ) ;
intern - > u . file . current_zval = NULL ;
}
} /* }}} */
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
static void spl_filesystem_object_free_storage ( void * object TSRMLS_DC ) /* { { { */
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) object ;
2003-07-16 15:13:23 +00:00
2006-03-08 20:30:12 +00:00
if ( intern - > oth_handler & & intern - > oth_handler - > dtor ) {
intern - > oth_handler - > dtor ( intern TSRMLS_CC ) ;
2006-03-08 20:06:16 +00:00
}
2006-03-29 15:08:52 +00:00
zend_object_std_dtor ( & intern - > std TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
if ( intern - > _path . v ) {
efree ( intern - > _path . v ) ;
2003-07-16 15:13:23 +00:00
}
2007-01-16 23:52:14 +00:00
if ( intern - > file_name . v ) {
2007-01-17 21:23:55 +00:00
efree ( intern - > file_name . v ) ;
2003-12-13 14:40:56 +00:00
}
2005-10-08 15:55:04 +00:00
switch ( intern - > type ) {
case SPL_FS_INFO :
break ;
case SPL_FS_DIR :
if ( intern - > u . dir . dirp ) {
php_stream_close ( intern - > u . dir . dirp ) ;
2006-11-12 17:56:14 +00:00
intern - > u . dir . dirp = NULL ;
2005-10-08 15:55:04 +00:00
}
2007-01-17 21:23:55 +00:00
if ( intern - > u . dir . sub_path . v ) {
efree ( intern - > u . dir . sub_path . v ) ;
2005-10-08 15:55:04 +00:00
}
break ;
case SPL_FS_FILE :
if ( intern - > u . file . stream ) {
if ( intern - > u . file . zcontext ) {
/* zend_list_delref(Z_RESVAL_P(intern->zcontext));*/
}
if ( ! intern - > u . file . stream - > is_persistent ) {
php_stream_free ( intern - > u . file . stream , PHP_STREAM_FREE_CLOSE ) ;
} else {
php_stream_free ( intern - > u . file . stream , PHP_STREAM_FREE_CLOSE_PERSISTENT ) ;
}
if ( intern - > u . file . open_mode ) {
efree ( intern - > u . file . open_mode ) ;
}
2008-05-20 21:46:13 +00:00
if ( intern - > orig_path ) {
efree ( intern - > orig_path ) ;
}
2005-10-08 15:55:04 +00:00
}
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
break ;
2005-03-31 21:51:46 +00:00
}
2003-07-16 15:13:23 +00:00
efree ( object ) ;
2005-10-08 15:55:04 +00:00
} /* }}} */
2003-11-09 14:05:36 +00:00
/* {{{ spl_ce_dir_object_new */
/* creates the object by
- allocating memory
- initializing the object members
- storing the object
- setting it ' s handlers
called from
- clone
- new
*/
2005-10-08 15:55:04 +00:00
static zend_object_value spl_filesystem_object_new_ex ( zend_class_entry * class_type , spl_filesystem_object * * obj TSRMLS_DC )
2003-07-16 15:13:23 +00:00
{
zend_object_value retval ;
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern ;
2003-07-16 15:13:23 +00:00
zval * tmp ;
2005-10-08 15:55:04 +00:00
intern = emalloc ( sizeof ( spl_filesystem_object ) ) ;
memset ( intern , 0 , sizeof ( spl_filesystem_object ) ) ;
2006-03-08 20:30:12 +00:00
/* intern->type = SPL_FS_INFO; done by set 0 */
2006-02-13 10:23:59 +00:00
intern - > file_class = spl_ce_SplFileObject ;
intern - > info_class = spl_ce_SplFileInfo ;
2005-03-07 00:40:57 +00:00
if ( obj ) * obj = intern ;
2003-07-16 15:13:23 +00:00
2006-03-29 15:08:52 +00:00
zend_object_std_init ( & intern - > std , class_type TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
zend_hash_copy ( intern - > std . properties , & class_type - > default_properties , ( copy_ctor_func_t ) zval_add_ref , ( void * ) & tmp , sizeof ( zval * ) ) ;
2005-10-08 15:55:04 +00:00
retval . handle = zend_objects_store_put ( intern , ( zend_objects_store_dtor_t ) zend_objects_destroy_object , ( zend_objects_free_object_storage_t ) spl_filesystem_object_free_storage , NULL TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
retval . handlers = & spl_filesystem_object_handlers ;
2003-07-16 15:13:23 +00:00
return retval ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_object_new */
/* See spl_filesystem_object_new_ex */
static zend_object_value spl_filesystem_object_new ( zend_class_entry * class_type TSRMLS_DC )
2003-07-19 09:49:28 +00:00
{
2005-10-08 15:55:04 +00:00
return spl_filesystem_object_new_ex ( class_type , NULL TSRMLS_CC ) ;
2003-07-19 09:49:28 +00:00
}
/* }}} */
2008-01-30 23:49:49 +00:00
PHPAPI zstr spl_filesystem_object_get_path ( spl_filesystem_object * intern , int * len , zend_uchar * type TSRMLS_DC ) /* { { { */
{
if ( intern - > type = = SPL_FS_DIR ) {
if ( php_stream_is ( intern - > u . dir . dirp , & php_glob_stream_ops ) ) {
2008-01-31 11:09:50 +00:00
zstr ret ;
2008-01-30 23:49:49 +00:00
if ( type ) {
* type = IS_STRING ;
}
ret . s = php_glob_stream_get_path ( intern - > u . dir . dirp , 0 , len ) ;
return ret ;
}
}
if ( len ) {
* len = intern - > _path_len ;
}
if ( type ) {
* type = intern - > _path_type ;
}
return intern - > _path ;
} /* }}} */
2005-10-08 15:55:04 +00:00
static inline void spl_filesystem_object_get_file_name ( spl_filesystem_object * intern TSRMLS_DC ) /* { { { */
{
2008-01-30 23:49:49 +00:00
zstr path ;
zend_uchar path_type ;
2009-03-10 23:27:59 +00:00
char slash = SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_UNIXPATHS ) ? ' / ' : DEFAULT_SLASH ;
2008-07-24 08:52:24 +00:00
2007-01-19 00:36:11 +00:00
if ( ! intern - > file_name . v ) {
2005-10-08 15:55:04 +00:00
switch ( intern - > type ) {
case SPL_FS_INFO :
case SPL_FS_FILE :
php_error_docref ( NULL TSRMLS_CC , E_ERROR , " Object not initialized " ) ;
break ;
case SPL_FS_DIR :
2008-01-30 23:49:49 +00:00
path = spl_filesystem_object_get_path ( intern , NULL , & path_type TSRMLS_CC ) ;
2008-02-02 22:53:05 +00:00
intern - > file_name_len = zspprintf ( path_type , & intern - > file_name , 0 , " %R%c%s " ,
path_type , path ,
2008-07-24 08:52:24 +00:00
slash , intern - > u . dir . entry . d_name ) ;
2008-01-30 23:49:49 +00:00
intern - > file_name_type = path_type ;
2005-10-08 15:55:04 +00:00
break ;
}
}
} /* }}} */
2007-03-03 23:41:43 +00:00
static int spl_filesystem_dir_read ( spl_filesystem_object * intern TSRMLS_DC ) /* { { { */
{
if ( ! intern - > u . dir . dirp | | ! php_stream_readdir ( intern - > u . dir . dirp , & intern - > u . dir . entry ) ) {
intern - > u . dir . entry . d_name [ 0 ] = ' \0 ' ;
return 0 ;
} else {
return 1 ;
}
}
/* }}} */
2008-02-02 22:53:05 +00:00
# define IS_SLASH_AT(type, zs, pos) (type == IS_UNICODE ? IS_U_SLASH(zs.u[pos]) : IS_SLASH(zs.s[pos]))
2008-05-16 13:22:02 +00:00
static inline int spl_filesystem_is_dot ( const char * d_name ) /* { { { */
{
return ! strcmp ( d_name , " . " ) | | ! strcmp ( d_name , " .. " ) ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_open */
2003-11-09 14:05:36 +00:00
/* open a directory resource */
2007-01-16 23:52:14 +00:00
static void spl_filesystem_dir_open ( spl_filesystem_object * intern , zend_uchar type , zstr path , int path_len TSRMLS_DC )
2003-07-19 09:49:28 +00:00
{
2008-02-02 22:53:05 +00:00
int options = REPORT_ERRORS ;
2009-03-10 23:27:59 +00:00
int skip_dots = SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_SKIPDOTS ) ;
2008-02-02 22:53:05 +00:00
# if HELLY_0
if ( php_stream_is ( intern - > u . dir . dirp , & php_glob_stream_ops ) ) {
2007-03-03 21:41:56 +00:00
options | = STREAM_USE_GLOB_DIR_OPEN ;
}
2008-02-02 22:53:05 +00:00
# endif
2007-03-03 21:41:56 +00:00
2005-10-08 15:55:04 +00:00
intern - > type = SPL_FS_DIR ;
2008-01-30 23:49:49 +00:00
intern - > _path_type = type ;
intern - > _path_len = path_len ;
2007-03-03 21:41:56 +00:00
intern - > u . dir . dirp = php_stream_u_opendir ( type , path , path_len , options , NULL ) ;
2003-07-19 09:49:28 +00:00
2008-11-06 01:07:05 +00:00
if ( intern - > _path_len > 1 & & IS_SLASH_AT ( type , path , intern - > _path_len - 1 ) ) {
2008-01-30 23:49:49 +00:00
intern - > _path = ezstrndup ( type , path , - - intern - > _path_len ) ;
2004-10-30 14:33:25 +00:00
} else {
2008-01-30 23:49:49 +00:00
intern - > _path = ezstrndup ( type , path , intern - > _path_len ) ;
2004-10-30 14:33:25 +00:00
}
2005-10-08 15:55:04 +00:00
intern - > u . dir . index = 0 ;
2003-07-19 09:49:28 +00:00
2008-04-09 19:00:48 +00:00
if ( EG ( exception ) | | intern - > u . dir . dirp = = NULL ) {
2003-07-19 09:49:28 +00:00
/* throw exception: should've been already happened */
2005-10-08 15:55:04 +00:00
intern - > u . dir . entry . d_name [ 0 ] = ' \0 ' ;
2003-07-19 09:49:28 +00:00
} else {
2008-05-16 13:22:02 +00:00
do {
spl_filesystem_dir_read ( intern TSRMLS_CC ) ;
} while ( skip_dots & & spl_filesystem_is_dot ( intern - > u . dir . entry . d_name ) ) ;
2003-07-19 09:49:28 +00:00
}
}
/* }}} */
2005-10-08 15:55:04 +00:00
static int spl_filesystem_file_open ( spl_filesystem_object * intern , int use_include_path , int silent TSRMLS_DC ) /* { { { */
{
intern - > type = SPL_FS_FILE ;
intern - > u . file . context = php_stream_context_from_zval ( intern - > u . file . zcontext , 0 ) ;
2007-01-16 23:52:14 +00:00
intern - > u . file . stream = php_stream_u_open_wrapper ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , intern - > u . file . open_mode , ( use_include_path ? USE_PATH : 0 ) | REPORT_ERRORS , NULL , intern - > u . file . context ) ;
2005-10-08 15:55:04 +00:00
2006-07-15 13:01:44 +00:00
if ( ! intern - > file_name_len | | ! intern - > u . file . stream ) {
2005-10-08 15:55:04 +00:00
if ( ! EG ( exception ) ) {
2007-01-16 23:52:14 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Cannot open file '%R' " , intern - > file_name_type , intern - > file_name_len ? intern - > file_name : EMPTY_ZSTR ) ;
2005-10-08 15:55:04 +00:00
}
2007-01-16 23:52:14 +00:00
intern - > file_name = NULL_ZSTR ; /* until here it is not a copy */
2005-10-08 15:55:04 +00:00
intern - > u . file . open_mode = NULL ;
return FAILURE ;
}
if ( intern - > u . file . zcontext ) {
zend_list_addref ( Z_RESVAL_P ( intern - > u . file . zcontext ) ) ;
}
2008-11-06 01:07:05 +00:00
if ( intern - > file_name_len > 1 & & IS_SLASH_AT ( intern - > file_name_type , intern - > file_name , intern - > file_name_len - 1 ) ) {
2006-07-15 13:01:44 +00:00
intern - > file_name_len - - ;
}
2008-05-20 21:46:13 +00:00
/* NOTE: Works as long as stream->orig_path is not unicode aware, might
* break later . */
intern - > orig_path = estrndup ( intern - > u . file . stream - > orig_path , strlen ( intern - > u . file . stream - > orig_path ) ) ;
2007-01-16 23:52:14 +00:00
intern - > file_name = ezstrndup ( intern - > file_name_type , intern - > file_name , intern - > file_name_len ) ;
2005-10-08 15:55:04 +00:00
intern - > u . file . open_mode = estrndup ( intern - > u . file . open_mode , intern - > u . file . open_mode_len ) ;
/* avoid reference counting in debug mode, thus do it manually */
ZVAL_RESOURCE ( & intern - > u . file . zresource , php_stream_get_resource_id ( intern - > u . file . stream ) ) ;
2007-10-07 05:15:07 +00:00
Z_SET_REFCOUNT ( intern - > u . file . zresource , 1 ) ;
2006-07-15 14:31:51 +00:00
intern - > u . file . delimiter = ' , ' ;
intern - > u . file . enclosure = ' " ' ;
2005-10-08 15:55:04 +00:00
zend_hash_find ( & intern - > std . ce - > function_table , " getcurrentline " , sizeof ( " getcurrentline " ) , ( void * * ) & intern - > u . file . func_getCurr ) ;
return SUCCESS ;
} /* }}} */
/* {{{ spl_filesystem_object_clone */
2003-11-09 14:05:36 +00:00
/* Local zend_object_value creation (on stack)
Load the ' other ' object
2005-10-08 15:55:04 +00:00
Create a new empty object ( See spl_filesystem_object_new_ex )
2003-11-09 14:05:36 +00:00
Open the directory
Clone other members ( properties )
*/
2005-10-08 15:55:04 +00:00
static zend_object_value spl_filesystem_object_clone ( zval * zobject TSRMLS_DC )
2003-07-19 09:49:28 +00:00
{
zend_object_value new_obj_val ;
zend_object * old_object ;
zend_object * new_object ;
zend_object_handle handle = Z_OBJ_HANDLE_P ( zobject ) ;
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern ;
2005-10-08 18:57:17 +00:00
spl_filesystem_object * source ;
2008-05-15 17:22:03 +00:00
int index ;
2008-05-16 13:22:02 +00:00
int skip_dots ;
2003-07-19 09:49:28 +00:00
old_object = zend_objects_get_address ( zobject TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
source = ( spl_filesystem_object * ) old_object ;
2005-10-08 15:55:04 +00:00
2009-03-10 23:27:59 +00:00
skip_dots = SPL_HAS_FLAG ( source - > flags , SPL_FILE_DIR_SKIPDOTS ) ;
2008-05-16 13:22:02 +00:00
2005-10-08 15:55:04 +00:00
new_obj_val = spl_filesystem_object_new_ex ( old_object - > ce , & intern TSRMLS_CC ) ;
2003-07-19 09:49:28 +00:00
new_object = & intern - > std ;
2008-05-16 13:22:02 +00:00
intern - > flags = source - > flags ;
2005-10-08 18:57:17 +00:00
switch ( source - > type ) {
2005-10-08 15:55:04 +00:00
case SPL_FS_INFO :
2008-01-30 23:49:49 +00:00
intern - > _path_type = source - > _path_type ;
intern - > _path_len = source - > _path_len ;
intern - > _path = ezstrndup ( source - > _path_type , source - > _path , source - > _path_len ) ;
2007-01-17 22:43:53 +00:00
intern - > file_name_type = source - > file_name_type ;
2005-10-08 18:57:17 +00:00
intern - > file_name_len = source - > file_name_len ;
2007-01-16 23:52:14 +00:00
intern - > file_name = ezstrndup ( source - > file_name_type , source - > file_name , intern - > file_name_len ) ;
2005-10-08 15:55:04 +00:00
break ;
case SPL_FS_DIR :
2008-01-30 23:49:49 +00:00
spl_filesystem_dir_open ( intern , source - > _path_type , source - > _path , source - > _path_len TSRMLS_CC ) ;
2008-05-15 17:22:03 +00:00
/* read until we hit the position in which we were before */
for ( index = 0 ; index < source - > u . dir . index ; + + index ) {
2008-05-16 13:22:02 +00:00
do {
spl_filesystem_dir_read ( intern TSRMLS_CC ) ;
} while ( skip_dots & & spl_filesystem_is_dot ( intern - > u . dir . entry . d_name ) ) ;
2008-05-15 17:22:03 +00:00
}
intern - > u . dir . index = index ;
2005-10-08 15:55:04 +00:00
break ;
case SPL_FS_FILE :
php_error_docref ( NULL TSRMLS_CC , E_ERROR , " An object of class %v cannot be cloned " , old_object - > ce - > name ) ;
break ;
}
2005-11-01 16:54:44 +00:00
intern - > file_class = source - > file_class ;
intern - > info_class = source - > info_class ;
2006-02-27 22:31:07 +00:00
intern - > oth = source - > oth ;
2006-03-08 20:30:12 +00:00
intern - > oth_handler = source - > oth_handler ;
2003-07-19 09:49:28 +00:00
zend_objects_clone_members ( new_object , new_obj_val , old_object , handle TSRMLS_CC ) ;
2006-03-08 20:30:12 +00:00
if ( intern - > oth_handler & & intern - > oth_handler - > clone ) {
intern - > oth_handler - > clone ( source , intern TSRMLS_CC ) ;
}
2003-07-19 09:49:28 +00:00
return new_obj_val ;
}
/* }}} */
2007-01-16 23:52:14 +00:00
void spl_filesystem_info_set_filename ( spl_filesystem_object * intern , zend_uchar type , zstr path , int len , int use_copy TSRMLS_DC ) /* { { { */
2005-10-10 21:06:54 +00:00
{
2007-01-16 23:52:14 +00:00
zstr p1 , p2 ;
2005-10-10 21:06:54 +00:00
2007-01-17 22:43:53 +00:00
intern - > file_name_type = type ;
2007-01-16 23:52:14 +00:00
intern - > file_name = use_copy ? ezstrndup ( type , path , len ) : path ;
2005-10-10 21:06:54 +00:00
intern - > file_name_len = len ;
2008-07-08 22:40:30 +00:00
while ( 1 ) {
if ( type = = IS_UNICODE ) {
p1 . u = u_strrchr ( intern - > file_name . u , ' / ' ) ;
} else {
p1 . s = strrchr ( intern - > file_name . s , ' / ' ) ;
}
2006-02-02 15:10:23 +00:00
# if defined(PHP_WIN32) || defined(NETWARE)
2008-07-08 22:40:30 +00:00
if ( type = = IS_UNICODE ) {
p2 . u = u_strrchr ( intern - > file_name . u , ' \\ ' ) ;
} else {
p2 . s = strrchr ( intern - > file_name . s , ' \\ ' ) ;
}
2006-02-02 15:10:23 +00:00
# else
2008-07-08 22:40:30 +00:00
p2 . v = 0 ;
2006-02-02 15:10:23 +00:00
# endif
2008-07-08 22:40:30 +00:00
if ( p1 . v | | p2 . v ) {
zstr slash_pos ;
if ( type = = IS_UNICODE ) {
slash_pos . u = ( p1 . u > p2 . u ? p1 . u : p2 . u ) ;
2008-11-06 01:07:05 +00:00
if ( IS_SLASH_AT ( type , intern - > file_name , intern - > file_name_len - 1 ) & & intern - > file_name_len > 1 ) {
2008-07-08 22:40:30 +00:00
intern - > file_name_len = slash_pos . u - intern - > file_name . u ;
intern - > file_name . u [ intern - > file_name_len ] = 0 ;
continue ;
}
intern - > _path_len = slash_pos . u - intern - > file_name . u ;
} else {
slash_pos . s = ( p1 . s > p2 . s ? p1 . s : p2 . s ) ;
2008-11-06 01:07:05 +00:00
if ( IS_SLASH_AT ( type , intern - > file_name , intern - > file_name_len - 1 ) & & intern - > file_name_len > 1 ) {
2008-07-08 22:40:30 +00:00
intern - > file_name_len = slash_pos . s - intern - > file_name . s ;
intern - > file_name . s [ intern - > file_name_len ] = 0 ;
continue ;
}
intern - > _path_len = slash_pos . s - intern - > file_name . s ;
}
2007-01-16 23:52:14 +00:00
} else {
2008-07-08 22:40:30 +00:00
intern - > _path_len = 0 ;
2007-01-16 23:52:14 +00:00
}
2008-07-08 22:40:30 +00:00
break ;
2005-10-10 21:06:54 +00:00
}
2008-07-08 22:40:30 +00:00
2008-01-30 23:49:49 +00:00
intern - > _path_type = type ;
intern - > _path = ezstrndup ( type , path , intern - > _path_len ) ;
2005-10-10 21:06:54 +00:00
} /* }}} */
2007-01-16 23:52:14 +00:00
static spl_filesystem_object * spl_filesystem_object_create_info ( spl_filesystem_object * source , zend_uchar file_type , zstr file_path , int file_path_len , int use_copy , zend_class_entry * ce , zval * return_value TSRMLS_DC ) /* { { { */
2005-10-10 21:06:54 +00:00
{
spl_filesystem_object * intern ;
2006-02-27 22:31:07 +00:00
zval * arg1 ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2008-02-02 22:53:05 +00:00
2007-01-16 23:52:14 +00:00
if ( ! file_path . v | | ! file_path_len ) {
2007-02-19 20:32:39 +00:00
# if defined(PHP_WIN32)
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Cannot create SplFileInfo for empty path " ) ;
2007-10-05 09:38:54 +00:00
if ( file_path . v & & ! use_copy ) {
2007-01-16 23:52:14 +00:00
efree ( file_path . v ) ;
2005-10-10 21:06:54 +00:00
}
2007-02-19 20:32:39 +00:00
# else
if ( file_path . v & & ! use_copy ) {
efree ( file_path . v ) ;
}
use_copy = 1 ;
file_path_len = 1 ;
file_path . s = " / " ;
file_type = IS_STRING ;
# endif
2005-10-10 21:06:54 +00:00
return NULL ;
}
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
2006-02-27 22:31:07 +00:00
ce = ce ? ce : source - > info_class ;
return_value - > value . obj = spl_filesystem_object_new_ex ( ce , & intern TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
Z_TYPE_P ( return_value ) = IS_OBJECT ;
2006-02-27 22:31:07 +00:00
if ( ce - > constructor - > common . scope ! = spl_ce_SplFileInfo ) {
MAKE_STD_ZVAL ( arg1 ) ;
2007-01-16 23:52:14 +00:00
ZVAL_ZSTRL ( arg1 , file_type , file_path , file_path_len , use_copy ) ;
2006-02-27 22:31:07 +00:00
zend_call_method_with_1_params ( & return_value , ce , & ce - > constructor , " __construct " , NULL , arg1 ) ;
zval_ptr_dtor ( & arg1 ) ;
} else {
2007-01-16 23:52:14 +00:00
spl_filesystem_info_set_filename ( intern , file_type , file_path , file_path_len , use_copy TSRMLS_CC ) ;
2006-02-27 22:31:07 +00:00
}
2005-10-10 21:06:54 +00:00
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
return intern ;
} /* }}} */
2005-11-01 16:54:44 +00:00
static spl_filesystem_object * spl_filesystem_object_create_type ( int ht , spl_filesystem_object * source , int type , zend_class_entry * ce , zval * return_value TSRMLS_DC ) /* { { { */
2005-10-08 18:57:17 +00:00
{
spl_filesystem_object * intern ;
zend_bool use_include_path = 0 ;
2006-02-27 22:31:07 +00:00
zval * arg1 , * arg2 ;
2008-08-08 22:06:42 +00:00
zend_error_handling error_handling ;
2005-10-08 18:57:17 +00:00
2008-08-08 22:06:42 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
switch ( source - > type ) {
case SPL_FS_INFO :
case SPL_FS_FILE :
break ;
case SPL_FS_DIR :
if ( ! source - > u . dir . entry . d_name [ 0 ] ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Could not open file " ) ;
2008-08-08 22:06:42 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
return NULL ;
2005-10-08 18:57:17 +00:00
}
}
switch ( type ) {
case SPL_FS_INFO :
2006-02-27 22:31:07 +00:00
ce = ce ? ce : source - > info_class ;
return_value - > value . obj = spl_filesystem_object_new_ex ( ce , & intern TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
Z_TYPE_P ( return_value ) = IS_OBJECT ;
2006-02-27 22:31:07 +00:00
2005-10-08 18:57:17 +00:00
spl_filesystem_object_get_file_name ( source TSRMLS_CC ) ;
2006-02-27 22:31:07 +00:00
if ( ce - > constructor - > common . scope ! = spl_ce_SplFileInfo ) {
MAKE_STD_ZVAL ( arg1 ) ;
2007-01-16 23:52:14 +00:00
ZVAL_ZSTRL ( arg1 , source - > file_name_type , source - > file_name , source - > file_name_len , 1 ) ;
2006-02-27 22:31:07 +00:00
zend_call_method_with_1_params ( & return_value , ce , & ce - > constructor , " __construct " , NULL , arg1 ) ;
zval_ptr_dtor ( & arg1 ) ;
} else {
2008-01-30 23:49:49 +00:00
intern - > _path = spl_filesystem_object_get_path ( source , & intern - > _path_len , & intern - > _path_type TSRMLS_CC ) ;
intern - > _path = ezstrndup ( intern - > _path_type , intern - > _path , intern - > _path_len ) ;
2007-01-17 22:43:53 +00:00
intern - > file_name_type = source - > file_name_type ;
intern - > file_name_len = source - > file_name_len ;
intern - > file_name = ezstrndup ( source - > file_name_type , source - > file_name , source - > file_name_len ) ;
2006-02-27 22:31:07 +00:00
}
2005-10-08 18:57:17 +00:00
break ;
case SPL_FS_FILE :
2006-02-27 22:31:07 +00:00
ce = ce ? ce : source - > file_class ;
return_value - > value . obj = spl_filesystem_object_new_ex ( ce , & intern TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
Z_TYPE_P ( return_value ) = IS_OBJECT ;
spl_filesystem_object_get_file_name ( source TSRMLS_CC ) ;
2006-02-27 22:31:07 +00:00
if ( ce - > constructor - > common . scope ! = spl_ce_SplFileObject ) {
MAKE_STD_ZVAL ( arg1 ) ;
MAKE_STD_ZVAL ( arg2 ) ;
2007-01-16 23:52:14 +00:00
ZVAL_ZSTRL ( arg1 , source - > file_name_type , source - > file_name , source - > file_name_len , 1 ) ;
2006-02-27 22:31:07 +00:00
ZVAL_STRINGL ( arg2 , " r " , 1 , 1 ) ;
zend_call_method_with_2_params ( & return_value , ce , & ce - > constructor , " __construct " , NULL , arg1 , arg2 ) ;
zval_ptr_dtor ( & arg1 ) ;
zval_ptr_dtor ( & arg2 ) ;
} else {
2008-01-30 23:49:49 +00:00
intern - > _path = spl_filesystem_object_get_path ( source , & intern - > _path_len , & intern - > _path_type TSRMLS_CC ) ;
intern - > _path = ezstrndup ( intern - > _path_type , intern - > _path , intern - > _path_len ) ;
2007-01-17 22:43:53 +00:00
intern - > file_name_type = source - > file_name_type ;
intern - > file_name_len = source - > file_name_len ;
intern - > file_name = source - > file_name ;
2006-02-27 22:31:07 +00:00
intern - > u . file . open_mode = " r " ;
intern - > u . file . open_mode_len = 1 ;
if ( ht & & zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |sbr " ,
& intern - > u . file . open_mode , & intern - > u . file . open_mode_len ,
& use_include_path , & intern - > u . file . zcontext ) = = FAILURE ) {
2008-08-08 22:06:42 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2006-02-27 22:31:07 +00:00
intern - > u . file . open_mode = NULL ;
2008-09-11 15:22:17 +00:00
intern - > file_name . v = NULL ;
2006-02-27 22:31:07 +00:00
zval_dtor ( return_value ) ;
Z_TYPE_P ( return_value ) = IS_NULL ;
return NULL ;
}
if ( spl_filesystem_file_open ( intern , use_include_path , 0 TSRMLS_CC ) = = FAILURE ) {
2008-08-08 22:06:42 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2006-02-27 22:31:07 +00:00
zval_dtor ( return_value ) ;
Z_TYPE_P ( return_value ) = IS_NULL ;
return NULL ;
}
2005-10-08 18:57:17 +00:00
}
2006-01-15 00:17:08 +00:00
break ;
2005-10-08 18:57:17 +00:00
case SPL_FS_DIR :
2008-08-08 22:06:42 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Operation not supported " ) ;
2005-10-10 21:06:54 +00:00
return NULL ;
2005-10-08 18:57:17 +00:00
}
2008-08-08 22:06:42 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
return NULL ;
2005-10-08 18:57:17 +00:00
} /* }}} */
2007-03-04 12:02:16 +00:00
static int spl_filesystem_is_invalid_or_dot ( const char * d_name ) /* { { { */
{
return d_name [ 0 ] = = ' \0 ' | | spl_filesystem_is_dot ( d_name ) ;
}
/* }}} */
2008-07-08 22:40:30 +00:00
static zstr spl_filesystem_object_get_pathname ( spl_filesystem_object * intern , int * len , zend_uchar * type TSRMLS_DC ) { /* {{{ */
switch ( intern - > type ) {
case SPL_FS_INFO :
case SPL_FS_FILE :
* len = intern - > file_name_len ;
* type = intern - > file_name_type ;
return intern - > file_name ;
case SPL_FS_DIR :
if ( intern - > u . dir . entry . d_name [ 0 ] ) {
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
* len = intern - > file_name_len ;
* type = intern - > file_name_type ;
return intern - > file_name ;
}
}
* len = 0 ;
* type = IS_STRING ;
return intern - > file_name ; /* dummy */
}
/* }}} */
2007-01-20 16:19:20 +00:00
static HashTable * spl_filesystem_object_get_debug_info ( zval * obj , int * is_temp TSRMLS_DC ) /* { { { { */
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( obj TSRMLS_CC ) ;
HashTable * rv ;
zval * tmp , zrv ;
zstr pnstr ;
int pnlen ;
char stmp [ 2 ] ;
2008-02-02 22:53:05 +00:00
int path_len ;
zstr path ;
zend_uchar path_type ;
2007-01-20 16:19:20 +00:00
* is_temp = 1 ;
ALLOC_HASHTABLE ( rv ) ;
ZEND_INIT_SYMTABLE_EX ( rv , zend_hash_num_elements ( intern - > std . properties ) + 3 , 0 ) ;
INIT_PZVAL ( & zrv ) ;
Z_ARRVAL ( zrv ) = rv ;
2008-02-02 22:53:05 +00:00
2007-01-20 16:19:20 +00:00
zend_hash_copy ( rv , intern - > std . properties , ( copy_ctor_func_t ) zval_add_ref , ( void * ) & tmp , sizeof ( zval * ) ) ;
2008-07-08 22:40:30 +00:00
path = spl_filesystem_object_get_pathname ( intern , & path_len , & path_type TSRMLS_CC ) ;
2007-01-20 16:19:20 +00:00
pnstr = spl_gen_private_prop_name ( spl_ce_SplFileInfo , " pathName " , sizeof ( " pathName " ) - 1 , & pnlen TSRMLS_CC ) ;
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , path_type , path , path_len , 1 ) ;
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
if ( intern - > file_name . v ) {
pnstr = spl_gen_private_prop_name ( spl_ce_SplFileInfo , " fileName " , sizeof ( " fileName " ) - 1 , & pnlen TSRMLS_CC ) ;
2008-07-08 22:40:30 +00:00
path = spl_filesystem_object_get_path ( intern , & path_len , & path_type TSRMLS_CC ) ;
if ( path_len & & path_len < intern - > file_name_len ) {
if ( intern - > file_name_type = = IS_UNICODE ) {
path . u = intern - > file_name . u + path_len + 1 ;
} else {
path . s = intern - > file_name . s + path_len + 1 ;
}
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , intern - > file_name_type , path , intern - > file_name_len - ( path_len + 1 ) , 1 ) ;
2008-07-08 22:40:30 +00:00
} else {
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , intern - > file_name_type , intern - > file_name , intern - > file_name_len , 1 ) ;
2008-07-08 22:40:30 +00:00
}
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
}
2008-01-30 23:49:49 +00:00
if ( intern - > type = = SPL_FS_DIR ) {
2008-02-02 22:53:05 +00:00
pnstr = spl_gen_private_prop_name ( spl_ce_DirectoryIterator , " glob " , sizeof ( " glob " ) - 1 , & pnlen TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
if ( php_stream_is ( intern - > u . dir . dirp , & php_glob_stream_ops ) ) {
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , intern - > _path_type , intern - > _path , intern - > _path_len , 1 ) ;
2008-01-30 23:49:49 +00:00
} else {
2009-03-26 20:02:53 +00:00
add_u_assoc_bool_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , 0 ) ;
2008-01-30 23:49:49 +00:00
}
efree ( pnstr . v ) ;
2007-01-20 16:19:20 +00:00
pnstr = spl_gen_private_prop_name ( spl_ce_RecursiveDirectoryIterator , " subPathName " , sizeof ( " subPathName " ) - 1 , & pnlen TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
if ( intern - > u . dir . sub_path . v ) {
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , intern - > u . dir . sub_path_type , intern - > u . dir . sub_path , intern - > u . dir . sub_path_len , 1 ) ;
2008-01-30 23:49:49 +00:00
} else {
2009-03-26 20:02:53 +00:00
add_u_assoc_zstrl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , IS_UNICODE , EMPTY_ZSTR , 0 , 1 ) ;
2008-01-30 23:49:49 +00:00
}
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
}
if ( intern - > type = = SPL_FS_FILE ) {
pnstr = spl_gen_private_prop_name ( spl_ce_SplFileObject , " openMode " , sizeof ( " openMode " ) - 1 , & pnlen TSRMLS_CC ) ;
2009-03-26 20:02:53 +00:00
add_u_assoc_stringl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , intern - > u . file . open_mode , intern - > u . file . open_mode_len , 1 ) ;
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
stmp [ 1 ] = ' \0 ' ;
stmp [ 0 ] = intern - > u . file . delimiter ;
pnstr = spl_gen_private_prop_name ( spl_ce_SplFileObject , " delimiter " , sizeof ( " delimiter " ) - 1 , & pnlen TSRMLS_CC ) ;
2009-03-26 20:02:53 +00:00
add_u_assoc_stringl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , stmp , 1 , 1 ) ;
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
stmp [ 0 ] = intern - > u . file . enclosure ;
pnstr = spl_gen_private_prop_name ( spl_ce_SplFileObject , " enclosure " , sizeof ( " enclosure " ) - 1 , & pnlen TSRMLS_CC ) ;
2009-03-26 20:02:53 +00:00
add_u_assoc_stringl_ex ( & zrv , IS_UNICODE , pnstr , pnlen + 1 , stmp , 1 , 1 ) ;
2007-01-20 16:19:20 +00:00
efree ( pnstr . v ) ;
}
return rv ;
}
/* }}}} */
2008-02-02 22:53:05 +00:00
# define DIT_CTOR_FLAGS 0x00000001
# define DIT_CTOR_GLOB 0x00000002
UChar u_glob [ sizeof ( " glob:// " ) ] ;
2009-03-10 23:27:59 +00:00
void spl_filesystem_object_construct ( INTERNAL_FUNCTION_PARAMETERS , long ctor_flags ) /* { { { */
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern ;
2007-01-16 23:52:14 +00:00
zstr path ;
2008-02-02 22:53:05 +00:00
int parsed , len ;
2007-01-16 23:52:14 +00:00
zend_uchar path_type ;
2008-02-04 19:33:03 +00:00
long flags ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2007-01-16 23:52:14 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( ctor_flags , DIT_CTOR_FLAGS ) ) {
2008-02-13 12:01:16 +00:00
flags = SPL_FILE_DIR_KEY_AS_PATHNAME | SPL_FILE_DIR_CURRENT_AS_FILEINFO ;
2008-02-02 22:53:05 +00:00
parsed = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " t|l " , & path , & len , & path_type , & flags ) ;
} else {
2008-02-04 19:33:03 +00:00
flags = SPL_FILE_DIR_KEY_AS_PATHNAME | SPL_FILE_DIR_CURRENT_AS_SELF ;
2008-02-02 22:53:05 +00:00
parsed = zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " t " , & path , & len , & path_type ) ;
}
2008-05-16 13:22:02 +00:00
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_SKIPDOTS ) ) {
2008-05-16 13:22:02 +00:00
flags | = SPL_FILE_DIR_SKIPDOTS ;
}
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( ctor_flags , SPL_FILE_DIR_UNIXPATHS ) ) {
2008-07-24 08:52:24 +00:00
flags | = SPL_FILE_DIR_UNIXPATHS ;
}
2008-02-02 22:53:05 +00:00
if ( parsed = = FAILURE ) {
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
return ;
}
2006-01-23 15:24:41 +00:00
if ( ! len ) {
2006-03-07 20:22:12 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Directory name must not be empty. " ) ;
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2006-03-07 20:22:12 +00:00
return ;
2006-01-23 15:24:41 +00:00
}
2005-10-08 15:55:04 +00:00
intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-05-16 13:22:02 +00:00
intern - > flags = flags ;
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( ctor_flags , DIT_CTOR_GLOB ) & & (
2008-02-02 22:53:05 +00:00
( path_type = = IS_STRING & & strstr ( path . s , " glob:// " ) ! = path . s ) | |
( path_type = = IS_UNICODE & & u_strstr ( path . u , u_glob ) ! = path . u )
) ) {
len = zspprintf ( path_type , & path , 0 , " glob://%R " , path_type , path ) ;
spl_filesystem_dir_open ( intern , path_type , path , len TSRMLS_CC ) ;
efree ( path . v ) ;
} else {
spl_filesystem_dir_open ( intern , path_type , path , len TSRMLS_CC ) ;
}
2007-01-16 23:52:14 +00:00
2006-02-13 10:23:59 +00:00
intern - > u . dir . is_recursive = instanceof_function ( intern - > std . ce , spl_ce_RecursiveDirectoryIterator TSRMLS_CC ) ? 1 : 0 ;
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
}
/* }}} */
2008-02-02 22:53:05 +00:00
/* {{{ proto void DirectoryIterator::__construct(string path) U
Cronstructs a new dir iterator from a path . */
SPL_METHOD ( DirectoryIterator , __construct )
{
spl_filesystem_object_construct ( INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 ) ;
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void DirectoryIterator::rewind() U
2003-07-16 15:13:23 +00:00
Rewind dir back to the start */
2003-11-09 14:05:36 +00:00
SPL_METHOD ( DirectoryIterator , rewind )
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
2005-10-08 15:55:04 +00:00
intern - > u . dir . index = 0 ;
if ( intern - > u . dir . dirp ) {
php_stream_rewinddir ( intern - > u . dir . dirp ) ;
2003-07-16 15:13:23 +00:00
}
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( intern TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string DirectoryIterator::key() U
2003-07-16 15:13:23 +00:00
Return current dir entry */
2003-11-09 14:05:36 +00:00
SPL_METHOD ( DirectoryIterator , key )
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
2005-10-08 15:55:04 +00:00
if ( intern - > u . dir . dirp ) {
RETURN_LONG ( intern - > u . dir . index ) ;
2003-11-09 14:05:36 +00:00
} else {
RETURN_FALSE ;
}
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto DirectoryIterator DirectoryIterator::current() U
2003-11-09 14:05:36 +00:00
Return this ( needed for Iterator interface ) */
SPL_METHOD ( DirectoryIterator , current )
{
2003-11-29 18:31:24 +00:00
RETURN_ZVAL ( getThis ( ) , 1 , 0 ) ;
2003-07-16 15:13:23 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void DirectoryIterator::next() U
2003-07-16 15:13:23 +00:00
Move to next entry */
2003-11-09 14:05:36 +00:00
SPL_METHOD ( DirectoryIterator , next )
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2009-03-10 23:27:59 +00:00
int skip_dots = SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_SKIPDOTS ) ;
2003-07-16 15:13:23 +00:00
2005-10-08 15:55:04 +00:00
intern - > u . dir . index + + ;
2008-05-16 13:22:02 +00:00
do {
spl_filesystem_dir_read ( intern TSRMLS_CC ) ;
} while ( skip_dots & & spl_filesystem_is_dot ( intern - > u . dir . entry . d_name ) ) ;
2007-01-16 23:52:14 +00:00
if ( intern - > file_name . v ) {
efree ( intern - > file_name . v ) ;
intern - > file_name = NULL_ZSTR ;
2003-12-13 14:40:56 +00:00
}
2003-07-16 15:13:23 +00:00
}
/* }}} */
2008-07-19 11:20:04 +00:00
/* {{{ proto void DirectoryIterator::seek(int position)
Seek to the given position */
SPL_METHOD ( DirectoryIterator , seek )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
zval * retval = NULL ;
long pos ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & pos ) = = FAILURE ) {
return ;
}
if ( intern - > u . dir . index > pos ) {
/* we first rewind */
zend_call_method_with_0_params ( & this_ptr , Z_OBJCE_P ( getThis ( ) ) , & intern - > u . dir . func_rewind , " rewind " , & retval ) ;
if ( retval ) {
zval_ptr_dtor ( & retval ) ;
}
}
while ( intern - > u . dir . index < pos ) {
int valid = 0 ;
zend_call_method_with_0_params ( & this_ptr , Z_OBJCE_P ( getThis ( ) ) , & intern - > u . dir . func_valid , " valid " , & retval ) ;
if ( retval ) {
valid = zend_is_true ( retval ) ;
zval_ptr_dtor ( & retval ) ;
}
if ( ! valid ) {
break ;
}
zend_call_method_with_0_params ( & this_ptr , Z_OBJCE_P ( getThis ( ) ) , & intern - > u . dir . func_next , " next " , & retval ) ;
if ( retval ) {
zval_ptr_dtor ( & retval ) ;
}
}
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string DirectoryIterator::valid() U
2003-07-16 15:13:23 +00:00
Check whether dir contains more entries */
2004-03-08 17:33:31 +00:00
SPL_METHOD ( DirectoryIterator , valid )
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
2005-10-08 15:55:04 +00:00
RETURN_BOOL ( intern - > u . dir . entry . d_name [ 0 ] ! = ' \0 ' ) ;
2003-07-16 15:13:23 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileInfo::getPath() U
2005-10-08 18:57:17 +00:00
Return the path */
SPL_METHOD ( SplFileInfo , getPath )
2003-07-16 15:13:23 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
int path_len ;
zend_uchar path_type ;
zstr path = spl_filesystem_object_get_path ( intern , & path_len , & path_type TSRMLS_CC ) ;
2003-07-16 15:13:23 +00:00
2008-01-30 23:49:49 +00:00
RETURN_ZSTRL ( path_type , path , path_len , ZSTR_DUPLICATE ) ;
2003-07-16 15:13:23 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileInfo::getFilename() U
2005-10-08 18:57:17 +00:00
Return filename only */
SPL_METHOD ( SplFileInfo , getFilename )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
zstr ret , path ;
zend_uchar path_type ;
int path_len ;
2005-10-08 18:57:17 +00:00
2008-01-30 23:49:49 +00:00
path = spl_filesystem_object_get_path ( intern , & path_len , & path_type TSRMLS_CC ) ;
if ( path_len & & path_len < intern - > file_name_len ) {
2007-01-16 23:52:14 +00:00
if ( intern - > file_name_type = = IS_UNICODE ) {
2008-01-30 23:49:49 +00:00
ret . u = intern - > file_name . u + path_len + 1 ;
2007-01-16 23:52:14 +00:00
} else {
2008-01-30 23:49:49 +00:00
ret . s = intern - > file_name . s + path_len + 1 ;
2007-01-16 23:52:14 +00:00
}
2008-01-30 23:49:49 +00:00
RETURN_ZSTRL ( intern - > file_name_type , ret , intern - > file_name_len - ( path_len + 1 ) , ZSTR_DUPLICATE ) ;
2005-10-08 18:57:17 +00:00
} else {
2007-01-17 21:29:38 +00:00
RETURN_ZSTRL ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , ZSTR_DUPLICATE ) ;
2005-10-08 18:57:17 +00:00
}
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string DirectoryIterator::getFilename() U
2003-11-09 14:05:36 +00:00
Return filename of current dir entry */
SPL_METHOD ( DirectoryIterator , getFilename )
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
2007-01-16 23:52:14 +00:00
RETURN_RT_STRING ( intern - > u . dir . entry . d_name , ZSTR_DUPLICATE ) ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2007-03-03 14:37:17 +00:00
/* {{{ proto string SplFileInfo::getBasename([string $suffix]) U
Returns filename component of path */
SPL_METHOD ( SplFileInfo , getBasename )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-01-30 23:49:49 +00:00
zstr fname , suffix , path ;
int flen , slen = 0 , path_len ;
2008-09-12 16:24:12 +00:00
zend_uchar path_type , stype ;
2007-03-03 14:37:17 +00:00
suffix . v = 0 ;
if ( intern - > file_name_type = = IS_UNICODE ) {
2008-09-12 16:24:12 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |t " , & suffix , & slen , & stype ) = = FAILURE ) {
2007-03-03 14:37:17 +00:00
return ;
}
} else {
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s " , & suffix . s , & slen ) = = FAILURE ) {
return ;
}
}
2008-01-30 23:49:49 +00:00
path = spl_filesystem_object_get_path ( intern , & path_len , & path_type TSRMLS_CC ) ;
if ( path_len & & path_len < intern - > file_name_len ) {
2007-03-03 14:46:44 +00:00
if ( intern - > file_name_type = = IS_UNICODE ) {
2008-01-30 23:49:49 +00:00
fname . u = intern - > file_name . u + path_len + 1 ;
2007-03-03 14:46:44 +00:00
} else {
2008-01-30 23:49:49 +00:00
fname . s = intern - > file_name . s + path_len + 1 ;
2007-03-03 14:46:44 +00:00
}
2008-01-30 23:49:49 +00:00
flen = intern - > file_name_len - ( path_len + 1 ) ;
2007-03-03 14:46:44 +00:00
} else {
fname = intern - > file_name ;
flen = intern - > file_name_len ;
}
2007-03-03 14:37:17 +00:00
if ( intern - > file_name_type = = IS_UNICODE ) {
php_u_basename ( fname . u , flen , suffix . u , slen , & fname . u , & flen TSRMLS_CC ) ;
} else {
php_basename ( fname . s , flen , suffix . s , slen , & fname . s , & flen TSRMLS_CC ) ;
}
RETURN_ZSTRL ( intern - > file_name_type , fname , flen , 0 ) ;
}
/* }}}*/
/* {{{ proto string DirectoryIterator::getBasename([string $suffix]) U
Returns filename component of current dir entry */
SPL_METHOD ( DirectoryIterator , getBasename )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
char * suffix = 0 , * fname ;
int slen = 0 , flen ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |s " , & suffix , & slen ) = = FAILURE ) {
return ;
}
php_basename ( intern - > u . dir . entry . d_name , strlen ( intern - > u . dir . entry . d_name ) , suffix , slen , & fname , & flen TSRMLS_CC ) ;
RETURN_RT_STRINGL ( fname , flen , ZSTR_AUTOFREE ) ;
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileInfo::getPathname() U
2005-10-08 15:55:04 +00:00
Return path and filename */
SPL_METHOD ( SplFileInfo , getPathname )
2003-11-09 14:05:36 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-07-08 22:40:30 +00:00
zstr path ;
zend_uchar path_type ;
int path_len ;
2003-11-09 14:05:36 +00:00
2008-07-08 22:40:30 +00:00
path = spl_filesystem_object_get_pathname ( intern , & path_len , & path_type TSRMLS_CC ) ;
if ( path_len ) {
RETURN_ZSTRL ( path_type , path , path_len , ZSTR_DUPLICATE ) ;
2003-11-18 22:14:19 +00:00
}
2005-10-08 15:55:04 +00:00
RETURN_BOOL ( 0 ) ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2008-02-02 22:53:05 +00:00
/* {{{ proto string FilesystemIterator::key() U
2005-10-08 18:57:17 +00:00
Return getPathname ( ) or getFilename ( ) depending on flags */
2008-02-02 22:53:05 +00:00
SPL_METHOD ( FilesystemIterator , key )
2003-11-09 14:05:36 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
2008-02-04 19:33:03 +00:00
if ( SPL_FILE_DIR_KEY ( intern , SPL_FILE_DIR_KEY_AS_FILENAME ) ) {
2007-01-17 21:29:38 +00:00
RETURN_RT_STRING ( intern - > u . dir . entry . d_name , ZSTR_DUPLICATE ) ;
2005-10-08 18:57:17 +00:00
} else {
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
2007-01-16 23:52:14 +00:00
RETURN_ZSTRL ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , 1 ) ;
2005-10-08 18:57:17 +00:00
}
}
/* }}} */
2008-02-02 22:53:05 +00:00
/* {{{ proto string FilesystemIterator::current() U
2005-12-11 16:43:00 +00:00
Return getFilename ( ) , getFileInfo ( ) or $ this depending on flags */
2008-02-02 22:53:05 +00:00
SPL_METHOD ( FilesystemIterator , current )
2005-10-08 18:57:17 +00:00
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-02-04 19:33:03 +00:00
if ( SPL_FILE_DIR_CURRENT ( intern , SPL_FILE_DIR_CURRENT_AS_PATHNAME ) ) {
2005-11-27 13:07:18 +00:00
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
2007-01-17 21:29:38 +00:00
RETURN_ZSTRL ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , ZSTR_DUPLICATE ) ;
2008-02-04 19:33:03 +00:00
} else if ( SPL_FILE_DIR_CURRENT ( intern , SPL_FILE_DIR_CURRENT_AS_FILEINFO ) ) {
2005-10-08 18:57:17 +00:00
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
spl_filesystem_object_create_type ( 0 , intern , SPL_FS_INFO , NULL , return_value TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
} else {
2005-11-27 13:07:18 +00:00
RETURN_ZVAL ( getThis ( ) , 1 , 0 ) ;
/*RETURN_STRING(intern->u.dir.entry.d_name, 1);*/
2005-10-08 18:57:17 +00:00
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool DirectoryIterator::isDot() U
2003-11-09 14:05:36 +00:00
Returns true if current entry is ' . ' or ' . . ' */
SPL_METHOD ( DirectoryIterator , isDot )
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
2007-03-04 12:13:20 +00:00
RETURN_BOOL ( spl_filesystem_is_dot ( intern - > u . dir . entry . d_name ) ) ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileInfo::__construct(string file_name) U
2005-10-08 15:55:04 +00:00
Cronstructs a new SplFileInfo from a path . */
2008-08-08 22:06:42 +00:00
/* zend_replace_error_handling() is used to throw exceptions in case
2005-10-08 15:55:04 +00:00
the constructor fails . Here we use this to ensure the object
has a valid directory resource .
When the constructor gets called the object is already created
by the engine , so we must only call ' additional ' initializations .
*/
SPL_METHOD ( SplFileInfo , __construct )
{
spl_filesystem_object * intern ;
2007-01-16 23:52:14 +00:00
zstr path ;
2007-01-17 21:29:38 +00:00
int path_len ;
zend_uchar path_type ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2005-10-08 15:55:04 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2005-10-08 15:55:04 +00:00
2007-01-17 21:29:38 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " t " , & path , & path_len , & path_type ) = = FAILURE ) {
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-08 15:55:04 +00:00
return ;
}
intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2007-01-17 21:29:38 +00:00
spl_filesystem_info_set_filename ( intern , path_type , path , path_len , 1 TSRMLS_CC ) ;
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
2005-10-08 15:55:04 +00:00
/* intern->type = SPL_FS_INFO; already set */
}
/* }}} */
/* {{{ FileInfoFunction */
# define FileInfoFunction(func_name, func_num) \
SPL_METHOD ( SplFileInfo , func_name ) \
2003-12-13 14:40:56 +00:00
{ \
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ; \
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ; \
2003-12-13 14:40:56 +00:00
\
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ; \
2005-10-08 15:55:04 +00:00
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ; \
2007-01-16 23:52:14 +00:00
php_u_stat ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , func_num , FG ( default_context ) , return_value TSRMLS_CC ) ; \
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ; \
2003-12-13 14:40:56 +00:00
}
/* }}} */
2003-11-09 14:05:36 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getPerms() U
2003-12-13 14:40:56 +00:00
Get file permissions */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getPerms , FS_PERMS )
2003-12-13 14:40:56 +00:00
/* }}} */
2003-11-09 14:05:36 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getInode() U
2003-12-13 14:40:56 +00:00
Get file inode */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getInode , FS_INODE )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getSize() U
2003-12-13 14:40:56 +00:00
Get file size */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getSize , FS_SIZE )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getOwner() U
2003-12-13 14:40:56 +00:00
Get file owner */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getOwner , FS_OWNER )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getGroup() U
2003-12-13 14:40:56 +00:00
Get file group */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getGroup , FS_GROUP )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getATime() U
2003-12-13 14:40:56 +00:00
Get last access time of file */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getATime , FS_ATIME )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getMTime() U
2003-12-13 14:40:56 +00:00
Get last modification time of file */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getMTime , FS_MTIME )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileInfo::getCTime() U
2003-12-13 14:40:56 +00:00
Get inode modification time of file */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getCTime , FS_CTIME )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileInfo::getType() U
2003-12-13 14:40:56 +00:00
Get file type */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( getType , FS_TYPE )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isWritable() U
2003-12-13 14:40:56 +00:00
Returns true if file can be written */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isWritable , FS_IS_W )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isReadable() U
2003-12-13 14:40:56 +00:00
Returns true if file can be read */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isReadable , FS_IS_R )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isExecutable() U
2003-12-13 14:40:56 +00:00
Returns true if file is executable */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isExecutable , FS_IS_X )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isFile() U
2003-12-13 14:40:56 +00:00
Returns true if file is a regular file */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isFile , FS_IS_FILE )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isDir() U
2003-12-13 14:40:56 +00:00
Returns true if file is directory */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isDir , FS_IS_DIR )
2003-12-13 14:40:56 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileInfo::isLink() U
2003-12-13 14:40:56 +00:00
Returns true if file is symbolic link */
2005-10-08 15:55:04 +00:00
FileInfoFunction ( isLink , FS_IS_LINK )
2003-11-09 14:05:36 +00:00
/* }}} */
2007-02-26 22:32:57 +00:00
/* {{{ proto string SplFileInfo::getLinkTarget() U
Return the target of a symbolic link */
SPL_METHOD ( SplFileInfo , getLinkTarget )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
UChar * target ;
int ret , link_len , target_len ;
2009-07-29 17:31:25 +00:00
char * link = NULL , buff [ MAXPATHLEN ] ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2007-02-26 22:32:57 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2007-02-26 22:32:57 +00:00
if ( intern - > file_name_type = = IS_UNICODE ) {
php_stream_path_encode ( NULL , & link , & link_len , intern - > file_name . u , intern - > file_name_len , REPORT_ERRORS , FG ( default_context ) ) ;
} else {
link = intern - > file_name . s ;
}
2007-06-05 12:02:38 +00:00
# ifdef HAVE_SYMLINK
2009-07-29 17:31:25 +00:00
ret = link ? readlink ( link , buff , MAXPATHLEN - 1 ) : - 1 ;
2007-06-05 12:02:38 +00:00
# else
ret = - 1 ; /* always fail if not implemented */
# endif
2007-02-26 22:32:57 +00:00
2009-07-29 17:31:25 +00:00
if ( link & & intern - > file_name_type = = IS_UNICODE ) {
efree ( link ) ;
}
2007-02-26 22:32:57 +00:00
if ( ret = = - 1 ) {
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Unable to read link %R, error: %s " , intern - > file_name_type , intern - > file_name , strerror ( errno ) ) ;
RETVAL_FALSE ;
} else {
/* Append NULL to the end of the string */
buff [ ret ] = ' \0 ' ;
2009-03-26 20:02:53 +00:00
if ( SUCCESS = = php_stream_path_decode ( NULL , & target , & target_len , buff , ret , REPORT_ERRORS , FG ( default_context ) ) ) {
RETVAL_UNICODEL ( target , target_len , 0 ) ;
2007-02-26 22:32:57 +00:00
} else {
RETVAL_STRING ( buff , 1 ) ;
}
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2007-02-26 22:32:57 +00:00
}
/* }}} */
# if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
/* {{{ proto string SplFileInfo::getRealPath() U
Return the resolved path */
SPL_METHOD ( SplFileInfo , getRealPath )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
UChar * path ;
int filename_len , path_len ;
char * filename , buff [ MAXPATHLEN ] ;
2008-09-11 15:45:29 +00:00
zend_bool free_filename = 0 ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2007-02-26 22:32:57 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2007-02-26 22:32:57 +00:00
2007-08-21 22:43:38 +00:00
if ( intern - > type = = SPL_FS_DIR & & ! intern - > file_name . v & & intern - > u . dir . entry . d_name [ 0 ] ) {
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
}
2008-05-20 21:46:13 +00:00
if ( intern - > orig_path ) {
filename = intern - > orig_path ;
2007-02-26 22:32:57 +00:00
} else {
2008-05-20 21:46:13 +00:00
if ( intern - > file_name_type = = IS_UNICODE ) {
php_stream_path_encode ( NULL , & filename , & filename_len , intern - > file_name . u , intern - > file_name_len , REPORT_ERRORS , FG ( default_context ) ) ;
2008-09-11 15:45:29 +00:00
free_filename = filename ! = NULL ;
2008-05-20 21:46:13 +00:00
} else {
filename = intern - > file_name . s ;
}
2007-02-26 22:32:57 +00:00
}
2007-08-21 22:43:38 +00:00
if ( filename & & VCWD_REALPATH ( filename , buff ) ) {
2007-02-26 22:46:13 +00:00
# ifdef ZTS
if ( VCWD_ACCESS ( buff , F_OK ) ) {
RETVAL_FALSE ;
} else
# endif
2009-03-26 20:02:53 +00:00
if ( php_stream_path_decode ( NULL , & path , & path_len , buff , strlen ( buff ) , REPORT_ERRORS , FG ( default_context ) ) = = SUCCESS ) {
RETVAL_UNICODEL ( path , path_len , 0 ) ;
2007-02-26 22:32:57 +00:00
} else {
RETVAL_STRING ( buff , 1 ) ;
}
} else {
RETVAL_FALSE ;
}
2007-08-21 22:43:38 +00:00
2008-09-11 15:45:29 +00:00
if ( free_filename ) {
2007-08-21 22:43:38 +00:00
efree ( filename ) ;
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2007-02-26 22:32:57 +00:00
}
/* }}} */
# endif
2007-01-19 10:19:50 +00:00
/* {{{ proto SplFileObject SplFileInfo::openFile([string mode = 'r' [, bool use_include_path [, resource context]]]) U
2005-03-07 00:40:57 +00:00
Open the current file */
2005-10-08 15:55:04 +00:00
SPL_METHOD ( SplFileInfo , openFile )
2005-03-07 00:40:57 +00:00
{
2005-10-08 18:57:17 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-11-01 16:54:44 +00:00
spl_filesystem_object_create_type ( ht , intern , SPL_FS_FILE , NULL , return_value TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
}
2006-02-02 12:40:07 +00:00
/* }}} */
2005-03-07 00:40:57 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileInfo::setFileClass([string class_name]) U
2005-11-01 16:54:44 +00:00
Class to use in openFile ( ) */
SPL_METHOD ( SplFileInfo , setFileClass )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2006-02-13 10:23:59 +00:00
zend_class_entry * ce = spl_ce_SplFileObject ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2008-08-08 22:06:42 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_UnexpectedValueException , & error_handling TSRMLS_CC ) ;
2006-03-04 22:56:11 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |C " , & ce ) = = SUCCESS ) {
intern - > file_class = ce ;
2005-11-01 16:54:44 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
}
2006-02-02 12:40:07 +00:00
/* }}} */
2005-11-01 16:54:44 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileInfo::setInfoClass([string class_name]) U
2006-03-04 22:56:11 +00:00
Class to use in getFileInfo ( ) , getPathInfo ( ) */
2005-11-01 16:54:44 +00:00
SPL_METHOD ( SplFileInfo , setInfoClass )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2006-02-13 10:23:59 +00:00
zend_class_entry * ce = spl_ce_SplFileInfo ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2008-08-08 22:06:42 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_UnexpectedValueException , & error_handling TSRMLS_CC ) ;
2006-03-04 22:56:11 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |C " , & ce ) = = SUCCESS ) {
intern - > info_class = ce ;
2005-11-01 16:54:44 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
}
2006-02-02 12:40:07 +00:00
/* }}} */
2005-11-01 16:54:44 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto SplFileInfo SplFileInfo::getFileInfo([string $class_name]) U
2005-10-08 18:57:17 +00:00
Get / copy file info */
SPL_METHOD ( SplFileInfo , getFileInfo )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
zend_class_entry * ce = intern - > info_class ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2008-08-08 22:06:42 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_UnexpectedValueException , & error_handling TSRMLS_CC ) ;
2006-03-04 22:56:11 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |C " , & ce ) = = SUCCESS ) {
spl_filesystem_object_create_type ( ht , intern , SPL_FS_INFO , ce , return_value TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
}
2006-02-02 12:40:07 +00:00
/* }}} */
2005-03-07 00:40:57 +00:00
2007-01-19 10:19:50 +00:00
/* {{{ proto SplFileInfo SplFileInfo::getPathInfo([string $class_name]) U
2005-10-10 21:06:54 +00:00
Get / copy file info */
SPL_METHOD ( SplFileInfo , getPathInfo )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
zend_class_entry * ce = intern - > info_class ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2008-08-08 22:06:42 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_UnexpectedValueException , & error_handling TSRMLS_CC ) ;
2006-03-04 22:56:11 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |C " , & ce ) = = SUCCESS ) {
2008-01-30 23:49:49 +00:00
zend_uchar path_type ;
int path_len ;
2008-07-08 22:40:30 +00:00
zstr path = spl_filesystem_object_get_pathname ( intern , & path_len , & path_type TSRMLS_CC ) ;
if ( path_len ) {
spl_filesystem_object_create_info ( intern , path_type , path , path_len , 1 , ce , return_value TSRMLS_CC ) ;
}
2005-11-01 16:54:44 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-10 21:06:54 +00:00
}
2006-02-02 12:40:07 +00:00
/* }}} */
2005-10-10 21:06:54 +00:00
2008-02-02 22:53:05 +00:00
/* {{{ proto void FilesystemIterator::__construct(string path [, int flags])
2005-12-11 16:43:00 +00:00
Cronstructs a new dir iterator from a path . */
2008-02-02 22:53:05 +00:00
SPL_METHOD ( FilesystemIterator , __construct )
2005-12-11 16:43:00 +00:00
{
2008-05-16 13:22:02 +00:00
spl_filesystem_object_construct ( INTERNAL_FUNCTION_PARAM_PASSTHRU , DIT_CTOR_FLAGS | SPL_FILE_DIR_SKIPDOTS ) ;
2005-12-11 16:43:00 +00:00
}
/* }}} */
2008-02-02 22:53:05 +00:00
/* {{{ proto void FilesystemIterator::rewind() U
2003-11-09 23:00:50 +00:00
Rewind dir back to the start */
2008-02-02 22:53:05 +00:00
SPL_METHOD ( FilesystemIterator , rewind )
2003-11-09 23:00:50 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-11-09 23:00:50 +00:00
2005-10-08 15:55:04 +00:00
intern - > u . dir . index = 0 ;
if ( intern - > u . dir . dirp ) {
php_stream_rewinddir ( intern - > u . dir . dirp ) ;
2003-11-09 23:00:50 +00:00
}
do {
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( intern TSRMLS_CC ) ;
2007-03-04 12:02:16 +00:00
} while ( spl_filesystem_is_dot ( intern - > u . dir . entry . d_name ) ) ;
2003-11-09 23:00:50 +00:00
}
/* }}} */
2008-02-13 12:01:16 +00:00
/* {{{ proto int FilesystemIterator::getFlags() U
Get handling flags */
SPL_METHOD ( FilesystemIterator , getFlags )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2009-06-04 14:46:08 +00:00
RETURN_LONG ( intern - > flags & ( SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK ) ) ;
2008-02-13 12:01:16 +00:00
} /* }}} */
/* {{{ proto void FilesystemIterator::setFlags(long $flags) U
Set handling flags */
SPL_METHOD ( FilesystemIterator , setFlags )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
long flags ;
zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & flags ) ;
2009-06-04 14:46:08 +00:00
intern - > flags & = ~ ( SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK ) ;
intern - > flags | = ( ( SPL_FILE_DIR_KEY_MODE_MASK | SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK ) & flags ) ;
2008-02-13 12:01:16 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = false]) U
2003-11-09 14:05:36 +00:00
Returns whether current entry is a directory and not ' . ' or ' . . ' */
2003-11-18 22:14:19 +00:00
SPL_METHOD ( RecursiveDirectoryIterator , hasChildren )
2003-11-09 14:05:36 +00:00
{
2004-01-23 21:33:56 +00:00
zend_bool allow_links = 0 ;
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
2007-03-04 12:02:16 +00:00
if ( spl_filesystem_is_invalid_or_dot ( intern - > u . dir . entry . d_name ) ) {
2007-01-19 00:36:11 +00:00
RETURN_FALSE ;
2003-11-09 14:05:36 +00:00
} else {
2004-01-23 21:33:56 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |b " , & allow_links ) = = FAILURE ) {
return ;
}
2005-10-08 15:55:04 +00:00
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
2009-07-08 03:09:58 +00:00
if ( ! allow_links & & ! ( intern - > flags & SPL_FILE_DIR_FOLLOW_SYMLINKS ) ) {
2007-01-19 00:36:11 +00:00
php_u_stat ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , FS_IS_LINK , FG ( default_context ) , return_value TSRMLS_CC ) ;
2004-01-23 21:33:56 +00:00
if ( zend_is_true ( return_value ) ) {
2007-01-19 00:36:11 +00:00
RETURN_FALSE ;
2004-01-23 21:33:56 +00:00
}
}
2007-01-16 23:52:14 +00:00
php_u_stat ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , FS_IS_DIR , FG ( default_context ) , return_value TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
}
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto RecursiveDirectoryIterator DirectoryIterator::getChildren() U
2005-03-09 09:19:27 +00:00
Returns an iterator for the current entry if it is a directory */
2003-11-18 22:14:19 +00:00
SPL_METHOD ( RecursiveDirectoryIterator , getChildren )
2003-11-09 14:05:36 +00:00
{
2007-03-03 21:41:56 +00:00
zval zpath , zflags ;
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
spl_filesystem_object * subdir ;
2009-03-10 23:27:59 +00:00
char slash = SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_UNIXPATHS ) ? ' / ' : DEFAULT_SLASH ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
spl_filesystem_object_get_file_name ( intern TSRMLS_CC ) ;
2003-12-09 19:02:34 +00:00
2009-05-09 21:05:18 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_CURRENT_AS_PATHNAME ) ) {
RETURN_ZSTRL ( intern - > file_name_type , intern - > file_name , intern - > file_name_len , 1 ) ;
} else {
INIT_PZVAL ( & zflags ) ;
INIT_PZVAL ( & zpath ) ;
ZVAL_LONG ( & zflags , intern - > flags ) ;
ZVAL_ZSTRL ( & zpath , intern - > file_name_type , intern - > file_name , intern - > file_name_len , 1 ) ;
2007-03-03 21:41:56 +00:00
2009-05-09 21:05:18 +00:00
spl_instantiate_arg_ex2 ( Z_OBJCE_P ( getThis ( ) ) , & return_value , 0 , & zpath , & zflags TSRMLS_CC ) ;
2007-03-03 21:41:56 +00:00
2009-05-09 21:05:18 +00:00
zval_dtor ( & zpath ) ;
2003-11-09 14:05:36 +00:00
2009-05-09 21:05:18 +00:00
subdir = ( spl_filesystem_object * ) zend_object_store_get_object ( return_value TSRMLS_CC ) ;
if ( subdir ) {
if ( intern - > u . dir . sub_path . v & & intern - > u . dir . sub_path_len > 1 ) {
subdir - > u . dir . sub_path_type = intern - > u . dir . sub_path_type ;
subdir - > u . dir . sub_path_len = zspprintf ( intern - > u . dir . sub_path_type , & subdir - > u . dir . sub_path , 0 , " %R%c%s " , intern - > u . dir . sub_path_type , intern - > u . dir . sub_path , slash , intern - > u . dir . entry . d_name ) ;
} else {
subdir - > u . dir . sub_path_len = strlen ( intern - > u . dir . entry . d_name ) ;
subdir - > u . dir . sub_path_type = IS_STRING ;
subdir - > u . dir . sub_path . s = estrndup ( intern - > u . dir . entry . d_name , subdir - > u . dir . sub_path_len ) ;
}
subdir - > info_class = intern - > info_class ;
subdir - > file_class = intern - > file_class ;
subdir - > oth = intern - > oth ;
2005-03-31 21:51:46 +00:00
}
}
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void RecursiveDirectoryIterator::getSubPath() U
2005-03-31 21:51:46 +00:00
Get sub path */
SPL_METHOD ( RecursiveDirectoryIterator , getSubPath )
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-31 21:51:46 +00:00
2007-01-16 23:52:14 +00:00
if ( intern - > u . dir . sub_path . v ) {
2007-01-17 21:29:38 +00:00
RETURN_ZSTRL ( intern - > u . dir . sub_path_type , intern - > u . dir . sub_path , intern - > u . dir . sub_path_len , ZSTR_DUPLICATE ) ;
2005-03-31 21:51:46 +00:00
} else {
2009-05-25 14:32:15 +00:00
RETURN_EMPTY_UNICODE ( ) ;
2005-03-31 21:51:46 +00:00
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void RecursiveDirectoryIterator::getSubPathname() U
2005-03-31 23:02:20 +00:00
Get sub path and file name */
SPL_METHOD ( RecursiveDirectoryIterator , getSubPathname )
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2007-01-16 23:52:14 +00:00
zstr sub_name ;
2007-01-18 21:40:18 +00:00
int sub_len ;
2009-03-10 23:27:59 +00:00
char slash = SPL_HAS_FLAG ( intern - > flags , SPL_FILE_DIR_UNIXPATHS ) ? ' / ' : DEFAULT_SLASH ;
2005-03-31 23:02:20 +00:00
2007-01-18 21:40:18 +00:00
if ( intern - > u . dir . sub_path . v ) {
2008-07-24 08:52:24 +00:00
sub_len = zspprintf ( intern - > u . dir . sub_path_type , & sub_name , 0 , " %R%c%s " , intern - > u . dir . sub_path_type , intern - > u . dir . sub_path , slash , intern - > u . dir . entry . d_name ) ;
2007-01-18 21:40:18 +00:00
RETURN_ZSTRL ( intern - > u . dir . sub_path_type , sub_name , sub_len , 0 ) ;
2005-03-31 23:02:20 +00:00
} else {
2007-01-17 21:29:38 +00:00
RETURN_RT_STRING ( intern - > u . dir . entry . d_name , ZSTR_DUPLICATE ) ;
2005-03-31 23:02:20 +00:00
}
}
/* }}} */
2008-02-02 22:53:05 +00:00
/* {{{ proto int RecursiveDirectoryIterator::__construct(string path [, int flags])
Cronstructs a new dir iterator from a path . */
SPL_METHOD ( RecursiveDirectoryIterator , __construct )
{
spl_filesystem_object_construct ( INTERNAL_FUNCTION_PARAM_PASSTHRU , DIT_CTOR_FLAGS ) ;
}
/* }}} */
/* {{{ proto int GlobIterator::__construct(string path [, int flags]) U
Cronstructs a new dir iterator from a glob expression ( no glob : // needed). */
SPL_METHOD ( GlobIterator , __construct )
{
spl_filesystem_object_construct ( INTERNAL_FUNCTION_PARAM_PASSTHRU , DIT_CTOR_FLAGS | DIT_CTOR_GLOB ) ;
}
/* }}} */
/* {{{ proto int GlobIterator::cont() U
Return the number of directories and files found by globbing */
SPL_METHOD ( GlobIterator , count )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
if ( php_stream_is ( intern - > u . dir . dirp , & php_glob_stream_ops ) ) {
RETURN_LONG ( php_glob_stream_get_count ( intern - > u . dir . dirp , NULL ) ) ;
} else {
/* should not happen */
php_error_docref ( NULL TSRMLS_CC , E_ERROR , " GlobIterator lost glob state " ) ;
}
}
/* }}} */
2008-02-04 19:39:07 +00:00
/* {{{ forward declarations to the iterator handlers */
2005-10-08 15:55:04 +00:00
static void spl_filesystem_dir_it_dtor ( zend_object_iterator * iter TSRMLS_DC ) ;
static int spl_filesystem_dir_it_valid ( zend_object_iterator * iter TSRMLS_DC ) ;
static void spl_filesystem_dir_it_current_data ( zend_object_iterator * iter , zval * * * data TSRMLS_DC ) ;
2006-02-21 20:12:43 +00:00
static int spl_filesystem_dir_it_current_key ( zend_object_iterator * iter , zstr * str_key , uint * str_key_len , ulong * int_key TSRMLS_DC ) ;
2005-10-08 15:55:04 +00:00
static void spl_filesystem_dir_it_move_forward ( zend_object_iterator * iter TSRMLS_DC ) ;
static void spl_filesystem_dir_it_rewind ( zend_object_iterator * iter TSRMLS_DC ) ;
2003-11-09 14:05:36 +00:00
/* iterator handler table */
2005-10-08 15:55:04 +00:00
zend_object_iterator_funcs spl_filesystem_dir_it_funcs = {
spl_filesystem_dir_it_dtor ,
spl_filesystem_dir_it_valid ,
spl_filesystem_dir_it_current_data ,
spl_filesystem_dir_it_current_key ,
spl_filesystem_dir_it_move_forward ,
spl_filesystem_dir_it_rewind
2003-11-09 14:05:36 +00:00
} ;
2008-02-04 19:39:07 +00:00
/* }}} */
2003-11-09 14:05:36 +00:00
/* {{{ spl_ce_dir_get_iterator */
2006-02-05 23:31:47 +00:00
zend_object_iterator * spl_filesystem_dir_get_iterator ( zend_class_entry * ce , zval * object , int by_ref TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator ;
spl_filesystem_object * dir_object ;
2006-02-05 23:31:47 +00:00
if ( by_ref ) {
zend_error ( E_ERROR , " An iterator cannot be used with foreach by reference " ) ;
}
dir_object = ( spl_filesystem_object * ) zend_object_store_get_object ( object TSRMLS_CC ) ;
2006-11-12 17:56:14 +00:00
iterator = spl_filesystem_object_to_iterator ( dir_object ) ;
2003-11-09 14:05:36 +00:00
2008-02-02 22:53:05 +00:00
Z_SET_REFCOUNT_P ( object , Z_REFCOUNT_P ( object ) + 2 ) ;
2003-11-09 14:05:36 +00:00
iterator - > intern . data = ( void * ) object ;
2005-10-08 15:55:04 +00:00
iterator - > intern . funcs = & spl_filesystem_dir_it_funcs ;
2003-11-22 20:46:46 +00:00
iterator - > current = object ;
2003-11-09 14:05:36 +00:00
return ( zend_object_iterator * ) iterator ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_dtor */
static void spl_filesystem_dir_it_dtor ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
2008-03-13 19:45:22 +00:00
zval * zfree = ( zval * ) iterator - > intern . data ;
2003-11-09 14:05:36 +00:00
2006-11-12 17:56:14 +00:00
iterator - > intern . data = NULL ; /* mark as unused */
2008-03-13 19:45:22 +00:00
zval_ptr_dtor ( & iterator - > current ) ;
zval_ptr_dtor ( & zfree ) ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2008-02-04 19:39:07 +00:00
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_valid */
static int spl_filesystem_dir_it_valid ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( ( spl_filesystem_iterator * ) iter ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
return object - > u . dir . entry . d_name [ 0 ] ! = ' \0 ' ? SUCCESS : FAILURE ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_current_data */
static void spl_filesystem_dir_it_current_data ( zend_object_iterator * iter , zval * * * data TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
2003-11-09 14:05:36 +00:00
* data = & iterator - > current ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_current_key */
2006-02-21 20:12:43 +00:00
static int spl_filesystem_dir_it_current_key ( zend_object_iterator * iter , zstr * str_key , uint * str_key_len , ulong * int_key TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( ( spl_filesystem_iterator * ) iter ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
* int_key = object - > u . dir . index ;
2003-11-09 14:05:36 +00:00
return HASH_KEY_IS_LONG ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_move_forward */
static void spl_filesystem_dir_it_move_forward ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( ( spl_filesystem_iterator * ) iter ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
object - > u . dir . index + + ;
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( object TSRMLS_CC ) ;
2007-01-16 23:52:14 +00:00
if ( object - > file_name . v ) {
efree ( object - > file_name . v ) ;
object - > file_name = NULL_ZSTR ;
2003-12-13 14:40:56 +00:00
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_dir_it_rewind */
static void spl_filesystem_dir_it_rewind ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( ( spl_filesystem_iterator * ) iter ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
object - > u . dir . index = 0 ;
if ( object - > u . dir . dirp ) {
php_stream_rewinddir ( object - > u . dir . dirp ) ;
2003-11-09 14:05:36 +00:00
}
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( object TSRMLS_CC ) ;
2003-11-09 14:05:36 +00:00
}
/* }}} */
2005-10-08 18:57:17 +00:00
/* {{{ spl_filesystem_tree_it_dtor */
static void spl_filesystem_tree_it_dtor ( zend_object_iterator * iter TSRMLS_DC )
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
2008-03-13 19:45:22 +00:00
zval * zfree = ( zval * ) iterator - > intern . data ;
2005-10-08 18:57:17 +00:00
if ( iterator - > current ) {
zval_ptr_dtor ( & iterator - > current ) ;
}
2006-11-12 17:56:14 +00:00
iterator - > intern . data = NULL ; /* mark as unused */
2008-03-13 19:45:22 +00:00
/* free twice as we add ref twice */
zval_ptr_dtor ( & zfree ) ;
zval_ptr_dtor ( & zfree ) ;
2005-10-08 18:57:17 +00:00
}
/* }}} */
2008-02-04 19:39:07 +00:00
2005-10-08 18:57:17 +00:00
/* {{{ spl_filesystem_tree_it_current_data */
static void spl_filesystem_tree_it_current_data ( zend_object_iterator * iter , zval * * * data TSRMLS_DC )
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( iterator ) ;
2005-10-08 18:57:17 +00:00
2008-02-04 19:33:03 +00:00
if ( SPL_FILE_DIR_CURRENT ( object , SPL_FILE_DIR_CURRENT_AS_PATHNAME ) ) {
2005-11-27 13:07:18 +00:00
if ( ! iterator - > current ) {
ALLOC_INIT_ZVAL ( iterator - > current ) ;
spl_filesystem_object_get_file_name ( object TSRMLS_CC ) ;
2007-01-17 21:29:38 +00:00
ZVAL_ZSTRL ( iterator - > current , object - > file_name_type , object - > file_name , object - > file_name_len , ZSTR_DUPLICATE ) ;
2005-11-27 13:07:18 +00:00
}
* data = & iterator - > current ;
2008-02-04 19:33:03 +00:00
} else if ( SPL_FILE_DIR_CURRENT ( object , SPL_FILE_DIR_CURRENT_AS_FILEINFO ) ) {
2005-10-08 18:57:17 +00:00
if ( ! iterator - > current ) {
ALLOC_INIT_ZVAL ( iterator - > current ) ;
spl_filesystem_object_get_file_name ( object TSRMLS_CC ) ;
2005-11-01 16:54:44 +00:00
spl_filesystem_object_create_type ( 0 , object , SPL_FS_INFO , NULL , iterator - > current TSRMLS_CC ) ;
2005-10-08 18:57:17 +00:00
}
* data = & iterator - > current ;
} else {
* data = ( zval * * ) & iterator - > intern . data ;
}
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_tree_it_current_key */
2006-02-21 20:12:43 +00:00
static int spl_filesystem_tree_it_current_key ( zend_object_iterator * iter , zstr * str_key , uint * str_key_len , ulong * int_key TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( ( spl_filesystem_iterator * ) iter ) ;
2003-11-09 14:05:36 +00:00
2008-02-04 19:33:03 +00:00
if ( SPL_FILE_DIR_KEY ( object , SPL_FILE_DIR_KEY_AS_FILENAME ) ) {
2005-10-08 18:57:17 +00:00
* str_key_len = strlen ( object - > u . dir . entry . d_name ) + 1 ;
2006-02-21 20:12:43 +00:00
str_key - > s = estrndup ( object - > u . dir . entry . d_name , * str_key_len - 1 ) ;
2007-01-16 23:52:14 +00:00
return HASH_KEY_IS_STRING ;
2005-10-08 18:57:17 +00:00
} else {
spl_filesystem_object_get_file_name ( object TSRMLS_CC ) ;
* str_key_len = object - > file_name_len + 1 ;
2007-01-16 23:52:14 +00:00
* str_key = ezstrndup ( object - > file_name_type , object - > file_name , object - > file_name_len ) ;
return object - > file_name_type ;
2005-10-08 18:57:17 +00:00
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_tree_it_move_forward */
static void spl_filesystem_tree_it_move_forward ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( iterator ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
object - > u . dir . index + + ;
2003-11-18 22:14:19 +00:00
do {
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( object TSRMLS_CC ) ;
2007-03-04 12:02:16 +00:00
} while ( spl_filesystem_is_dot ( object - > u . dir . entry . d_name ) ) ;
2007-01-16 23:52:14 +00:00
if ( object - > file_name . v ) {
efree ( object - > file_name . v ) ;
object - > file_name = NULL_ZSTR ;
2003-12-13 14:40:56 +00:00
}
2005-10-08 18:57:17 +00:00
if ( iterator - > current ) {
zval_ptr_dtor ( & iterator - > current ) ;
iterator - > current = NULL ;
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_tree_it_rewind */
static void spl_filesystem_tree_it_rewind ( zend_object_iterator * iter TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator = ( spl_filesystem_iterator * ) iter ;
spl_filesystem_object * object = spl_filesystem_iterator_to_object ( iterator ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
object - > u . dir . index = 0 ;
if ( object - > u . dir . dirp ) {
php_stream_rewinddir ( object - > u . dir . dirp ) ;
2003-11-09 14:05:36 +00:00
}
2003-11-18 22:14:19 +00:00
do {
2007-03-03 23:41:43 +00:00
spl_filesystem_dir_read ( object TSRMLS_CC ) ;
2007-03-04 12:02:16 +00:00
} while ( spl_filesystem_is_dot ( object - > u . dir . entry . d_name ) ) ;
2005-10-08 18:57:17 +00:00
if ( iterator - > current ) {
zval_ptr_dtor ( & iterator - > current ) ;
iterator - > current = NULL ;
}
2003-11-09 14:05:36 +00:00
}
/* }}} */
2008-02-04 19:39:07 +00:00
/* {{{ iterator handler table */
2005-10-08 15:55:04 +00:00
zend_object_iterator_funcs spl_filesystem_tree_it_funcs = {
2005-10-08 18:57:17 +00:00
spl_filesystem_tree_it_dtor ,
2005-10-08 15:55:04 +00:00
spl_filesystem_dir_it_valid ,
2005-10-08 18:57:17 +00:00
spl_filesystem_tree_it_current_data ,
2005-10-08 15:55:04 +00:00
spl_filesystem_tree_it_current_key ,
spl_filesystem_tree_it_move_forward ,
spl_filesystem_tree_it_rewind
2003-11-09 14:05:36 +00:00
} ;
2008-02-04 19:39:07 +00:00
/* }}} */
2003-11-09 14:05:36 +00:00
/* {{{ spl_ce_dir_get_iterator */
2006-02-05 23:31:47 +00:00
zend_object_iterator * spl_filesystem_tree_get_iterator ( zend_class_entry * ce , zval * object , int by_ref TSRMLS_DC )
2003-11-09 14:05:36 +00:00
{
2006-11-12 17:56:14 +00:00
spl_filesystem_iterator * iterator ;
2006-02-05 23:31:47 +00:00
spl_filesystem_object * dir_object ;
if ( by_ref ) {
zend_error ( E_ERROR , " An iterator cannot be used with foreach by reference " ) ;
}
dir_object = ( spl_filesystem_object * ) zend_object_store_get_object ( object TSRMLS_CC ) ;
2006-11-12 17:56:14 +00:00
iterator = spl_filesystem_object_to_iterator ( dir_object ) ;
2003-11-09 14:05:36 +00:00
2008-03-13 19:45:22 +00:00
Z_SET_REFCOUNT_P ( object , Z_REFCOUNT_P ( object ) + 2 ) ;
2003-11-09 14:05:36 +00:00
iterator - > intern . data = ( void * ) object ;
2005-10-08 15:55:04 +00:00
iterator - > intern . funcs = & spl_filesystem_tree_it_funcs ;
2005-10-08 18:57:17 +00:00
iterator - > current = NULL ;
2003-11-09 14:05:36 +00:00
return ( zend_object_iterator * ) iterator ;
}
/* }}} */
2005-10-08 15:55:04 +00:00
/* {{{ spl_filesystem_object_cast */
2006-10-13 14:52:19 +00:00
static int spl_filesystem_object_cast ( zval * readobj , zval * writeobj , int type , void * extra TSRMLS_DC )
2003-11-22 20:46:46 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( readobj TSRMLS_CC ) ;
2009-06-24 08:53:44 +00:00
int ret ;
zval retval ;
zval * retval_ptr = & retval ;
2003-11-22 20:46:46 +00:00
2006-12-20 23:30:23 +00:00
switch ( intern - > type ) {
case SPL_FS_INFO :
case SPL_FS_FILE :
2007-01-16 23:52:14 +00:00
if ( type = = intern - > file_name_type ) {
2009-06-24 08:53:44 +00:00
ZVAL_ZSTRL ( retval_ptr , intern - > file_name_type , intern - > file_name , intern - > file_name_len , 1 ) ;
ret = SUCCESS ;
break ;
2007-01-16 23:52:14 +00:00
}
2006-12-20 23:30:23 +00:00
if ( type = = IS_STRING ) {
2009-06-24 08:53:44 +00:00
ZVAL_ZSTRL ( retval_ptr , intern - > file_name_type , intern - > file_name , intern - > file_name_len , ZSTR_DUPLICATE ) ;
zval_unicode_to_string_ex ( retval_ptr , ZEND_U_CONVERTER ( ( ( UConverter * ) extra ) ) TSRMLS_CC ) ;
ret = SUCCESS ;
break ;
2006-12-20 23:30:23 +00:00
}
2009-03-26 20:02:53 +00:00
if ( type = = IS_UNICODE ) {
2009-06-24 08:53:44 +00:00
ZVAL_ASCII_STRINGL ( retval_ptr , intern - > file_name . s , intern - > file_name_len , 1 ) ;
ret = SUCCESS ;
break ;
2006-12-20 23:30:23 +00:00
}
2009-06-24 08:53:44 +00:00
ZVAL_NULL ( retval_ptr ) ;
ret = FAILURE ;
2006-12-20 23:30:23 +00:00
break ;
case SPL_FS_DIR :
if ( type = = IS_STRING ) {
2009-06-24 08:53:44 +00:00
ZVAL_STRING ( retval_ptr , intern - > u . dir . entry . d_name , 1 ) ;
ret = SUCCESS ;
break ;
2005-10-08 15:55:04 +00:00
}
2009-03-26 20:02:53 +00:00
if ( type = = IS_UNICODE ) {
2009-06-24 08:53:44 +00:00
ZVAL_ASCII_STRING ( retval_ptr , intern - > u . dir . entry . d_name , 1 ) ;
ret = SUCCESS ;
break ;
2006-12-20 23:30:23 +00:00
}
2009-06-24 08:53:44 +00:00
default :
ZVAL_NULL ( retval_ptr ) ;
ret = FAILURE ;
break ;
}
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
2003-11-22 20:46:46 +00:00
}
2009-06-24 08:53:44 +00:00
ZVAL_ZVAL ( writeobj , retval_ptr , 0 , 0 ) ;
return ret ;
2003-11-22 20:46:46 +00:00
}
/* }}} */
2003-11-09 14:05:36 +00:00
2008-02-04 19:39:07 +00:00
/* {{{ declare method parameters */
2003-12-13 14:40:56 +00:00
/* supply a name and default to call by parameter */
2005-10-08 15:55:04 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_info___construct , 0 )
ZEND_ARG_INFO ( 0 , file_name )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2003-12-13 14:40:56 +00:00
2005-10-08 15:55:04 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_info_openFile , 0 , 0 , 0 )
2005-03-07 00:40:57 +00:00
ZEND_ARG_INFO ( 0 , open_mode )
ZEND_ARG_INFO ( 0 , use_include_path )
ZEND_ARG_INFO ( 0 , context )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2003-12-13 14:40:56 +00:00
2005-11-01 16:54:44 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_info_optinalFileClass , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , class_name )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-11-01 16:54:44 +00:00
2007-03-03 14:37:17 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_optinalSuffix , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , suffix )
ZEND_END_ARG_INFO ( )
2009-07-04 20:28:16 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_splfileinfo_void , 0 )
ZEND_END_ARG_INFO ( )
2003-12-13 14:40:56 +00:00
/* the method table */
/* each method can have its own parameters and visibility */
2007-09-27 18:28:44 +00:00
static const zend_function_entry spl_SplFileInfo_functions [ ] = {
2005-10-08 15:55:04 +00:00
SPL_ME ( SplFileInfo , __construct , arginfo_info___construct , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileInfo , getPath , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getFilename , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2007-03-03 14:37:17 +00:00
SPL_ME ( SplFileInfo , getBasename , arginfo_optinalSuffix , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileInfo , getPathname , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getPerms , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getInode , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getSize , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getOwner , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getGroup , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getATime , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getMTime , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getCTime , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getType , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isWritable , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isReadable , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isExecutable , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isFile , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isDir , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , isLink , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getLinkTarget , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2007-03-03 14:51:40 +00:00
# if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS)
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileInfo , getRealPath , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2007-03-03 14:51:40 +00:00
# endif
2005-11-01 16:54:44 +00:00
SPL_ME ( SplFileInfo , getFileInfo , arginfo_info_optinalFileClass , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , getPathInfo , arginfo_info_optinalFileClass , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , openFile , arginfo_info_openFile , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , setFileClass , arginfo_info_optinalFileClass , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileInfo , setInfoClass , arginfo_info_optinalFileClass , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_MA ( SplFileInfo , __toString , SplFileInfo , getPathname , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-10-08 15:55:04 +00:00
{ NULL , NULL , NULL }
} ;
2008-02-02 22:53:05 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_dir___construct , 0 )
2005-10-08 15:55:04 +00:00
ZEND_ARG_INFO ( 0 , path )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-10-08 15:55:04 +00:00
2008-07-19 11:20:04 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_dir_it_seek , 0 )
ZEND_ARG_INFO ( 0 , position )
ZEND_END_ARG_INFO ( ) ;
2005-10-08 15:55:04 +00:00
/* the method table */
/* each method can have its own parameters and visibility */
2007-09-27 18:28:44 +00:00
static const zend_function_entry spl_DirectoryIterator_functions [ ] = {
2003-12-13 14:40:56 +00:00
SPL_ME ( DirectoryIterator , __construct , arginfo_dir___construct , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( DirectoryIterator , getFilename , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2007-03-03 14:37:17 +00:00
SPL_ME ( DirectoryIterator , getBasename , arginfo_optinalSuffix , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( DirectoryIterator , isDot , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , rewind , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , valid , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , key , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , current , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , next , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2008-07-19 11:20:04 +00:00
SPL_ME ( DirectoryIterator , seek , arginfo_dir_it_seek , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_MA ( DirectoryIterator , __toString , DirectoryIterator , getFilename , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2003-12-13 14:40:56 +00:00
{ NULL , NULL , NULL }
} ;
2006-11-06 23:19:46 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_r_dir___construct , 0 , 0 , 1 )
2005-12-11 16:43:00 +00:00
ZEND_ARG_INFO ( 0 , path )
ZEND_ARG_INFO ( 0 , flags )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-12-11 16:43:00 +00:00
2006-11-06 23:19:46 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_r_dir_hasChildren , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , allow_links )
ZEND_END_ARG_INFO ( )
2008-02-13 12:01:16 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_r_dir_setFlags , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , flags )
ZEND_END_ARG_INFO ( )
2008-02-02 22:53:05 +00:00
static const zend_function_entry spl_FilesystemIterator_functions [ ] = {
SPL_ME ( FilesystemIterator , __construct , arginfo_r_dir___construct , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( FilesystemIterator , rewind , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( DirectoryIterator , next , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( FilesystemIterator , key , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( FilesystemIterator , current , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( FilesystemIterator , getFlags , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2008-02-13 12:01:16 +00:00
SPL_ME ( FilesystemIterator , setFlags , arginfo_r_dir_setFlags , ZEND_ACC_PUBLIC )
2008-02-02 22:53:05 +00:00
{ NULL , NULL , NULL }
} ;
2007-09-27 18:28:44 +00:00
static const zend_function_entry spl_RecursiveDirectoryIterator_functions [ ] = {
2005-12-11 16:43:00 +00:00
SPL_ME ( RecursiveDirectoryIterator , __construct , arginfo_r_dir___construct , ZEND_ACC_PUBLIC )
2006-11-06 23:19:46 +00:00
SPL_ME ( RecursiveDirectoryIterator , hasChildren , arginfo_r_dir_hasChildren , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( RecursiveDirectoryIterator , getChildren , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( RecursiveDirectoryIterator , getSubPath , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( RecursiveDirectoryIterator , getSubPathname , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2003-12-13 14:40:56 +00:00
{ NULL , NULL , NULL }
} ;
2008-02-02 22:53:05 +00:00
static const zend_function_entry spl_GlobIterator_functions [ ] = {
SPL_ME ( GlobIterator , __construct , arginfo_r_dir___construct , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( GlobIterator , count , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2008-02-02 22:53:05 +00:00
{ NULL , NULL , NULL }
} ;
2008-02-04 19:39:07 +00:00
/* }}} */
2008-02-02 22:53:05 +00:00
2005-10-08 15:55:04 +00:00
static int spl_filesystem_file_read ( spl_filesystem_object * intern , int silent TSRMLS_DC ) /* { { { */
2005-03-07 00:40:57 +00:00
{
char * buf ;
2006-04-06 19:11:06 +00:00
size_t line_len = 0 ;
2005-10-08 15:55:04 +00:00
long line_add = ( intern - > u . file . current_line | | intern - > u . file . current_zval ) ? 1 : 0 ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
2005-05-03 22:18:19 +00:00
2005-10-08 15:55:04 +00:00
if ( php_stream_eof ( intern - > u . file . stream ) ) {
2005-03-07 00:40:57 +00:00
if ( ! silent ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Cannot read from file %s " , intern - > file_name ) ;
2005-03-07 00:40:57 +00:00
}
return FAILURE ;
}
2006-04-06 19:11:06 +00:00
if ( intern - > u . file . max_line_len > 0 ) {
2006-12-26 17:40:20 +00:00
buf = safe_emalloc ( ( intern - > u . file . max_line_len + 1 ) , sizeof ( char ) , 0 ) ;
2006-04-28 19:03:58 +00:00
if ( php_stream_get_line ( intern - > u . file . stream , ZSTR ( buf ) , intern - > u . file . max_line_len , & line_len ) = = NULL ) {
2006-04-06 19:11:06 +00:00
efree ( buf ) ;
buf = NULL ;
} else {
buf [ line_len ] = ' \0 ' ;
}
} else {
2006-04-28 19:03:58 +00:00
buf = php_stream_get_line ( intern - > u . file . stream , NULL_ZSTR , 0 , & line_len ) ;
2006-04-06 19:11:06 +00:00
}
2005-05-03 21:11:26 +00:00
if ( ! buf ) {
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line = estrdup ( " " ) ;
intern - > u . file . current_line_len = 0 ;
2005-05-03 21:11:26 +00:00
} else {
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_DROP_NEW_LINE ) ) {
2005-05-03 21:11:26 +00:00
line_len = strcspn ( buf , " \r \n " ) ;
buf [ line_len ] = ' \0 ' ;
}
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line = buf ;
intern - > u . file . current_line_len = line_len ;
2005-03-07 00:40:57 +00:00
}
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line_num + = line_add ;
2005-03-07 00:40:57 +00:00
return SUCCESS ;
} /* }}} */
2006-03-09 23:03:08 +00:00
static int spl_filesystem_file_call ( spl_filesystem_object * intern , zend_function * func_ptr , int pass_num_args , zval * return_value , zval * arg2 TSRMLS_DC ) /* { { { */
{
zend_fcall_info fci ;
zend_fcall_info_cache fcic ;
zval z_fname ;
zval * zresource_ptr = & intern - > u . file . zresource , * retval ;
int result ;
int num_args = pass_num_args + ( arg2 ? 2 : 1 ) ;
zval * * * params = ( zval * * * ) safe_emalloc ( num_args , sizeof ( zval * * ) , 0 ) ;
params [ 0 ] = & zresource_ptr ;
if ( arg2 ) {
params [ 1 ] = & arg2 ;
}
zend_get_parameters_array_ex ( pass_num_args , params + ( arg2 ? 2 : 1 ) ) ;
ZVAL_STRING ( & z_fname , func_ptr - > common . function_name . s , 0 ) ;
fci . size = sizeof ( fci ) ;
fci . function_table = EG ( function_table ) ;
2008-11-27 19:02:45 +00:00
fci . object_ptr = NULL ;
2006-03-09 23:03:08 +00:00
fci . function_name = & z_fname ;
fci . retval_ptr_ptr = & retval ;
fci . param_count = num_args ;
fci . params = params ;
fci . no_separation = 1 ;
fci . symbol_table = NULL ;
fcic . initialized = 1 ;
fcic . function_handler = func_ptr ;
fcic . calling_scope = NULL ;
2008-07-25 08:53:11 +00:00
fcic . called_scope = NULL ;
2008-11-27 19:02:45 +00:00
fcic . object_ptr = NULL ;
2006-03-09 23:03:08 +00:00
result = zend_call_function ( & fci , & fcic TSRMLS_CC ) ;
ZVAL_ZVAL ( return_value , retval , 1 , 1 ) ;
efree ( params ) ;
return result ;
} /* }}} */
2008-02-04 19:39:07 +00:00
# define FileFunctionCall(func_name, pass_num_args, arg2) /* {{{ */ \
2006-03-09 23:03:08 +00:00
{ \
zend_function * func_ptr ; \
2008-07-02 10:46:52 +00:00
int ret ; \
ret = zend_ascii_hash_find ( EG ( function_table ) , # func_name , sizeof ( # func_name ) , ( void * * ) & func_ptr ) ; \
if ( ret ! = SUCCESS ) { \
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Internal error, function '%s' not found. Please report " , # func_name ) ; \
return ; \
} \
2006-03-09 23:03:08 +00:00
spl_filesystem_file_call ( intern , func_ptr , pass_num_args , return_value , arg2 TSRMLS_CC ) ; \
2008-02-04 19:39:07 +00:00
} /* }}} */
2006-03-09 23:03:08 +00:00
2007-10-03 10:31:04 +00:00
static int spl_filesystem_file_read_csv ( spl_filesystem_object * intern , char delimiter , char enclosure , char escape , zval * return_value TSRMLS_DC ) /* { { { */
2006-03-09 23:03:08 +00:00
{
2006-07-15 14:31:51 +00:00
int ret = SUCCESS ;
do {
ret = spl_filesystem_file_read ( intern , 1 TSRMLS_CC ) ;
2009-03-10 23:27:59 +00:00
} while ( ret = = SUCCESS & & ! intern - > u . file . current_line_len & & SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_SKIP_EMPTY ) ) ;
2006-07-15 14:31:51 +00:00
if ( ret = = SUCCESS ) {
size_t buf_len = intern - > u . file . current_line_len ;
char * buf = estrndup ( intern - > u . file . current_line , buf_len ) ;
2006-03-09 23:03:08 +00:00
2006-08-06 13:47:21 +00:00
if ( intern - > u . file . current_zval ) {
zval_ptr_dtor ( & intern - > u . file . current_zval ) ;
}
ALLOC_INIT_ZVAL ( intern - > u . file . current_zval ) ;
2007-10-03 10:31:04 +00:00
php_fgetcsv ( intern - > u . file . stream , delimiter , enclosure , escape , buf_len , buf , intern - > u . file . current_zval TSRMLS_CC ) ;
2006-08-06 13:47:21 +00:00
if ( return_value ) {
if ( Z_TYPE_P ( return_value ) ! = IS_NULL ) {
zval_dtor ( return_value ) ;
ZVAL_NULL ( return_value ) ;
}
ZVAL_ZVAL ( return_value , intern - > u . file . current_zval , 1 , 0 ) ;
2006-07-15 14:54:57 +00:00
}
2006-07-15 14:31:51 +00:00
}
return ret ;
2006-03-09 23:03:08 +00:00
}
/* }}} */
static int spl_filesystem_file_read_line_ex ( zval * this_ptr , spl_filesystem_object * intern , int silent TSRMLS_DC ) /* { { { */
2005-03-07 22:18:40 +00:00
{
2006-03-20 13:53:56 +00:00
zval * retval = NULL ;
2005-03-07 22:18:40 +00:00
2006-03-09 23:03:08 +00:00
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_CSV ) | | intern - > u . file . func_getCurr - > common . scope ! = spl_ce_SplFileObject ) {
2005-10-08 15:55:04 +00:00
if ( php_stream_eof ( intern - > u . file . stream ) ) {
2005-05-03 22:18:19 +00:00
if ( ! silent ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Cannot read from file %s " , intern - > file_name ) ;
2005-05-03 22:18:19 +00:00
}
return FAILURE ;
}
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_CSV ) ) {
2007-10-03 10:31:04 +00:00
return spl_filesystem_file_read_csv ( intern , intern - > u . file . delimiter , intern - > u . file . enclosure , intern - > u . file . escape , NULL TSRMLS_CC ) ;
2006-03-09 23:03:08 +00:00
} else {
zend_call_method_with_0_params ( & this_ptr , Z_OBJCE_P ( getThis ( ) ) , & intern - > u . file . func_getCurr , " getCurrentLine " , & retval ) ;
}
2005-03-07 22:18:40 +00:00
if ( retval ) {
2005-10-08 15:55:04 +00:00
if ( intern - > u . file . current_line | | intern - > u . file . current_zval ) {
intern - > u . file . current_line_num + + ;
2005-05-03 22:18:19 +00:00
}
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
if ( Z_TYPE_P ( retval ) = = IS_STRING ) {
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line = estrndup ( Z_STRVAL_P ( retval ) , Z_STRLEN_P ( retval ) ) ;
intern - > u . file . current_line_len = Z_STRLEN_P ( retval ) ;
2005-03-07 22:18:40 +00:00
} else {
2005-10-08 15:55:04 +00:00
MAKE_STD_ZVAL ( intern - > u . file . current_zval ) ;
ZVAL_ZVAL ( intern - > u . file . current_zval , retval , 1 , 0 ) ;
2005-03-07 22:18:40 +00:00
}
zval_ptr_dtor ( & retval ) ;
2005-05-03 22:18:19 +00:00
return SUCCESS ;
} else {
return FAILURE ;
2005-03-07 22:18:40 +00:00
}
} else {
2005-10-08 15:55:04 +00:00
return spl_filesystem_file_read ( intern , silent TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
}
} /* }}} */
2006-03-09 23:03:08 +00:00
static int spl_filesystem_file_is_empty_line ( spl_filesystem_object * intern TSRMLS_DC ) /* { { { */
{
if ( intern - > u . file . current_line ) {
return intern - > u . file . current_line_len = = 0 ;
} else if ( intern - > u . file . current_zval ) {
switch ( Z_TYPE_P ( intern - > u . file . current_zval ) ) {
case IS_STRING :
case IS_UNICODE :
return Z_STRLEN_P ( intern - > u . file . current_zval ) = = 0 ;
case IS_ARRAY :
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_CSV )
2006-03-09 23:03:08 +00:00
& & zend_hash_num_elements ( Z_ARRVAL_P ( intern - > u . file . current_zval ) ) = = 1 ) {
zval * * first = Z_ARRVAL_P ( intern - > u . file . current_zval ) - > pListHead - > pData ;
2008-02-04 19:33:03 +00:00
return ( Z_TYPE_PP ( first ) = = IS_STRING | | Z_TYPE_PP ( first ) = = IS_UNICODE )
2006-03-09 23:03:08 +00:00
& & Z_STRLEN_PP ( first ) = = 0 ;
}
return zend_hash_num_elements ( Z_ARRVAL_P ( intern - > u . file . current_zval ) ) = = 0 ;
case IS_NULL :
return 1 ;
default :
return 0 ;
}
} else {
return 1 ;
}
}
/* }}} */
static int spl_filesystem_file_read_line ( zval * this_ptr , spl_filesystem_object * intern , int silent TSRMLS_DC ) /* { { { */
{
int ret = spl_filesystem_file_read_line_ex ( this_ptr , intern , silent TSRMLS_CC ) ;
2009-03-10 23:27:59 +00:00
while ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_SKIP_EMPTY ) & & ret = = SUCCESS & & spl_filesystem_file_is_empty_line ( intern TSRMLS_CC ) ) {
2006-03-09 23:03:08 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
ret = spl_filesystem_file_read_line_ex ( this_ptr , intern , silent TSRMLS_CC ) ;
}
return ret ;
}
/* }}} */
static void spl_filesystem_file_rewind ( zval * this_ptr , spl_filesystem_object * intern TSRMLS_DC ) /* { { { */
2005-05-03 21:11:26 +00:00
{
2005-10-08 15:55:04 +00:00
if ( - 1 = = php_stream_rewind ( intern - > u . file . stream ) ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_RuntimeException , 0 TSRMLS_CC , " Cannot rewind file %s " , intern - > file_name ) ;
2005-05-03 21:11:26 +00:00
} else {
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
intern - > u . file . current_line_num = 0 ;
2005-05-03 21:11:26 +00:00
}
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2006-03-09 23:03:08 +00:00
spl_filesystem_file_read_line ( this_ptr , intern , 1 TSRMLS_CC ) ;
}
2005-05-03 21:11:26 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::__construct(string filename [, string mode = 'r' [, bool use_include_path [, resource context]]]]) U
2005-10-29 15:15:22 +00:00
Construct a new file object */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , __construct )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
zend_bool use_include_path = 0 ;
2007-01-16 23:52:14 +00:00
zstr p1 , p2 ;
2008-05-20 21:46:13 +00:00
char * tmp_path ;
int tmp_path_len ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2005-03-07 00:40:57 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
intern - > u . file . open_mode = " r " ;
intern - > u . file . open_mode_len = 1 ;
2005-03-07 00:40:57 +00:00
2007-01-16 23:52:14 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " t|sbr " ,
& intern - > file_name , & intern - > file_name_len , & intern - > file_name_type ,
2005-10-08 15:55:04 +00:00
& intern - > u . file . open_mode , & intern - > u . file . open_mode_len ,
& use_include_path , & intern - > u . file . zcontext ) = = FAILURE ) {
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
return ;
}
2005-12-08 19:53:43 +00:00
if ( spl_filesystem_file_open ( intern , use_include_path , 0 TSRMLS_CC ) = = SUCCESS ) {
2008-05-20 21:46:13 +00:00
tmp_path_len = strlen ( intern - > u . file . stream - > orig_path ) ;
2008-11-06 01:07:05 +00:00
if ( tmp_path_len > 1 & & IS_SLASH_AT ( IS_STRING , ZSTR ( intern - > u . file . stream - > orig_path ) , tmp_path_len - 1 ) ) {
2008-05-20 21:46:13 +00:00
tmp_path_len - - ;
2007-01-16 23:52:14 +00:00
}
2008-05-20 21:46:13 +00:00
tmp_path = estrndup ( intern - > u . file . stream - > orig_path , tmp_path_len ) ;
p1 . s = strrchr ( tmp_path , ' / ' ) ;
2006-02-02 15:10:23 +00:00
# if defined(PHP_WIN32) || defined(NETWARE)
2008-05-20 21:46:13 +00:00
p2 . s = strrchr ( tmp_path , ' \\ ' ) ;
2006-02-02 15:10:23 +00:00
# else
2007-01-16 23:52:14 +00:00
p2 . v = 0 ;
2006-02-02 15:10:23 +00:00
# endif
2008-05-20 21:46:13 +00:00
2007-01-16 23:52:14 +00:00
if ( p1 . v | | p2 . v ) {
2008-05-20 21:46:13 +00:00
intern - > _path_len = ( p1 . s > p2 . s ? p1 . s : p2 . s ) - tmp_path ;
2005-12-08 19:53:43 +00:00
} else {
2008-01-30 23:49:49 +00:00
intern - > _path_len = 0 ;
2005-12-08 19:53:43 +00:00
}
2008-05-20 21:46:13 +00:00
efree ( tmp_path ) ;
intern - > _path = ZSTR ( estrndup ( intern - > u . file . stream - > orig_path , intern - > _path_len ) ) ;
intern - > _path_type = IS_STRING ;
2005-10-08 18:57:17 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplTempFileObject::__construct([int max_memory]) U
2005-10-29 15:15:22 +00:00
Construct a new temp file object */
SPL_METHOD ( SplTempFileObject , __construct )
{
long max_memory = PHP_STREAM_MAX_MEM ;
2005-10-29 15:48:14 +00:00
char tmp_fname [ 48 ] ;
2005-10-29 15:15:22 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2008-11-19 01:59:07 +00:00
zend_error_handling error_handling ;
2005-10-29 15:15:22 +00:00
2008-11-19 01:59:07 +00:00
zend_replace_error_handling ( EH_THROW , spl_ce_RuntimeException , & error_handling TSRMLS_CC ) ;
2005-10-29 15:15:22 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |l " , & max_memory ) = = FAILURE ) {
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-29 15:15:22 +00:00
return ;
}
if ( max_memory < 0 ) {
2007-01-16 23:52:14 +00:00
intern - > file_name_type = IS_STRING ;
intern - > file_name . s = " php://memory " ;
2005-10-29 15:15:22 +00:00
intern - > file_name_len = 12 ;
} else if ( ZEND_NUM_ARGS ( ) ) {
2007-01-16 23:52:14 +00:00
intern - > file_name_type = IS_STRING ;
2005-10-29 15:15:22 +00:00
intern - > file_name_len = snprintf ( tmp_fname , sizeof ( tmp_fname ) , " php://temp/maxmemory:%ld " , max_memory ) ;
2007-01-16 23:52:14 +00:00
intern - > file_name . s = tmp_fname ;
2005-10-29 15:15:22 +00:00
} else {
2007-01-16 23:52:14 +00:00
intern - > file_name_type = IS_STRING ;
intern - > file_name . s = " php://temp " ;
2005-10-29 15:15:22 +00:00
intern - > file_name_len = 10 ;
}
intern - > u . file . open_mode = " wb " ;
intern - > u . file . open_mode_len = 1 ;
intern - > u . file . zcontext = NULL ;
2005-12-08 19:53:43 +00:00
if ( spl_filesystem_file_open ( intern , 0 , 0 TSRMLS_CC ) = = SUCCESS ) {
2008-01-30 23:49:49 +00:00
intern - > _path_type = IS_STRING ;
intern - > _path_len = 0 ;
intern - > _path . s = estrndup ( " " , 0 ) ;
2005-12-08 19:53:43 +00:00
}
2008-11-19 01:59:07 +00:00
zend_restore_error_handling ( & error_handling TSRMLS_CC ) ;
2005-10-29 15:15:22 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::rewind() U
2005-03-07 00:40:57 +00:00
Rewind the file and read the first line */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , rewind )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2006-03-09 23:03:08 +00:00
spl_filesystem_file_rewind ( getThis ( ) , intern TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::eof() U
2005-03-07 00:40:57 +00:00
Return whether end of file is reached */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , eof )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
RETURN_BOOL ( php_stream_eof ( intern - > u . file . stream ) ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::valid() U
2005-03-07 00:40:57 +00:00
Return ! eof ( ) */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , valid )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2006-03-09 23:03:08 +00:00
RETURN_BOOL ( intern - > u . file . current_line | | intern - > u . file . current_zval ) ;
} else {
RETVAL_BOOL ( ! php_stream_eof ( intern - > u . file . stream ) ) ;
}
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileObject::fgets() U
2005-03-07 00:40:57 +00:00
Rturn next line from file */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fgets )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
if ( spl_filesystem_file_read ( intern , 0 TSRMLS_CC ) = = FAILURE ) {
2005-03-07 00:40:57 +00:00
RETURN_FALSE ;
}
2005-10-08 15:55:04 +00:00
RETURN_STRINGL ( intern - > u . file . current_line , intern - > u . file . current_line_len , 1 ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileObject::current() U
2005-03-07 00:40:57 +00:00
Return current line from file */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , current )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2006-03-09 23:03:08 +00:00
if ( ! intern - > u . file . current_line & & ! intern - > u . file . current_zval ) {
2005-10-08 15:55:04 +00:00
spl_filesystem_file_read_line ( getThis ( ) , intern , 1 TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
}
2009-03-10 23:27:59 +00:00
if ( intern - > u . file . current_line & & ( ! SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_CSV ) | | ! intern - > u . file . current_zval ) ) {
2007-01-17 21:29:38 +00:00
RETURN_RT_STRINGL ( intern - > u . file . current_line , intern - > u . file . current_line_len , ZSTR_DUPLICATE ) ;
2005-10-08 15:55:04 +00:00
} else if ( intern - > u . file . current_zval ) {
RETURN_ZVAL ( intern - > u . file . current_zval , 1 , 0 ) ;
2005-03-07 00:40:57 +00:00
}
RETURN_FALSE ;
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::key() U
2005-03-07 00:40:57 +00:00
Return line number */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , key )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-05-03 22:18:19 +00:00
/* Do not read the next line to support correct counting with fgetc()
2005-03-07 22:18:40 +00:00
if ( ! intern - > current_line ) {
2005-10-08 15:55:04 +00:00
spl_filesystem_file_read_line ( getThis ( ) , intern , 1 TSRMLS_CC ) ;
2005-05-03 22:18:19 +00:00
} */
2005-10-08 15:55:04 +00:00
RETURN_LONG ( intern - > u . file . current_line_num ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::next() U
2005-03-07 00:40:57 +00:00
Read next line */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , next )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
2009-03-10 23:27:59 +00:00
if ( SPL_HAS_FLAG ( intern - > flags , SPL_FILE_OBJECT_READ_AHEAD ) ) {
2006-03-09 23:03:08 +00:00
spl_filesystem_file_read_line ( getThis ( ) , intern , 1 TSRMLS_CC ) ;
}
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line_num + + ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::setFlags(int flags) U
2005-03-07 00:40:57 +00:00
Set file handling flags */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , setFlags )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 18:57:17 +00:00
zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & intern - > flags ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::getFlags() U
2005-03-07 00:40:57 +00:00
Get file handling flags */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , getFlags )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2008-05-16 13:22:02 +00:00
RETURN_LONG ( intern - > flags & SPL_FILE_OBJECT_MASK ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto void SplFileObject::setMaxLineLen(int max_len) U
2005-03-07 00:40:57 +00:00
Set maximum line length */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , setMaxLineLen )
2005-03-07 00:40:57 +00:00
{
long max_len ;
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & max_len ) = = FAILURE ) {
return ;
}
if ( max_len < 0 ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_DomainException , 0 TSRMLS_CC , " Maximum line length must be greater than or equal zero " ) ;
2005-03-07 00:40:57 +00:00
return ;
}
2005-10-08 15:55:04 +00:00
intern - > u . file . max_line_len = max_len ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::getMaxLineLen() U
2005-03-07 00:40:57 +00:00
Get maximum line length */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , getMaxLineLen )
2005-03-07 00:40:57 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 00:40:57 +00:00
2005-10-08 15:55:04 +00:00
RETURN_LONG ( ( long ) intern - > u . file . max_line_len ) ;
2005-03-07 00:40:57 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileObject::hasChildren() U
2005-12-18 14:05:23 +00:00
Return false */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , hasChildren )
2005-03-07 00:40:57 +00:00
{
RETURN_FALSE ;
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileObject::getChildren() U
2005-03-07 00:40:57 +00:00
Read NULL */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , getChildren )
2005-03-07 00:40:57 +00:00
{
/* return NULL */
} /* }}} */
/* {{{ FileFunction */
# define FileFunction(func_name) \
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , func_name ) \
2005-03-07 00:40:57 +00:00
{ \
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ; \
2006-03-09 23:03:08 +00:00
FileFunctionCall ( func_name , ZEND_NUM_ARGS ( ) , NULL ) ; \
2005-03-07 00:40:57 +00:00
}
/* }}} */
2009-07-20 22:20:36 +00:00
/* {{{ proto array SplFileObject::fgetcsv([string delimiter [, string enclosure [, escape = '\\']]]) U
2005-03-07 00:40:57 +00:00
Return current line as csv */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fgetcsv )
2005-03-07 01:00:29 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2007-10-03 10:31:04 +00:00
char delimiter = intern - > u . file . delimiter , enclosure = intern - > u . file . enclosure , escape = intern - > u . file . escape ;
2008-10-21 22:06:49 +00:00
char * delim = NULL , * enclo = NULL , * esc = NULL ;
int d_len = 0 , e_len = 0 , esc_len = 0 ;
2006-03-09 23:03:08 +00:00
2007-10-03 10:31:04 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |sss " , & delim , & d_len , & enclo , & e_len , & esc , & esc_len ) = = SUCCESS ) {
2006-07-15 14:31:51 +00:00
switch ( ZEND_NUM_ARGS ( ) )
{
2007-10-05 09:38:54 +00:00
case 3 :
if ( esc_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " escape must be a character " ) ;
RETURN_FALSE ;
}
escape = esc [ 0 ] ;
2008-02-02 22:53:05 +00:00
/* no break */
2007-10-05 09:38:54 +00:00
case 2 :
if ( e_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " enclosure must be a character " ) ;
RETURN_FALSE ;
}
enclosure = enclo [ 0 ] ;
/* no break */
case 1 :
if ( d_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " delimiter must be a character " ) ;
RETURN_FALSE ;
}
delimiter = delim [ 0 ] ;
/* no break */
case 0 :
break ;
2006-07-15 14:31:51 +00:00
}
2007-10-03 10:31:04 +00:00
spl_filesystem_file_read_csv ( intern , delimiter , enclosure , escape , return_value TSRMLS_CC ) ;
2006-07-15 14:31:51 +00:00
}
2005-03-07 01:00:29 +00:00
}
2005-03-07 00:40:57 +00:00
/* }}} */
2007-10-03 10:31:04 +00:00
/* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, string enclosure = '"' [, string escape = '\\']]])
2006-07-15 14:50:38 +00:00
Set the delimiter and enclosure character used in fgetcsv */
SPL_METHOD ( SplFileObject , setCsvControl )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2007-10-03 10:31:04 +00:00
char delimiter = ' , ' , enclosure = ' " ' , escape = ' \\ ' ;
2008-10-21 22:06:49 +00:00
char * delim = NULL , * enclo = NULL , * esc = NULL ;
int d_len = 0 , e_len = 0 , esc_len = 0 ;
2006-07-15 14:50:38 +00:00
2007-10-03 10:31:04 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " |sss " , & delim , & d_len , & enclo , & e_len , & esc , & esc_len ) = = SUCCESS ) {
2006-07-15 14:50:38 +00:00
switch ( ZEND_NUM_ARGS ( ) )
{
2007-10-05 09:38:54 +00:00
case 3 :
if ( esc_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " escape must be a character " ) ;
RETURN_FALSE ;
}
escape = esc [ 0 ] ;
/* no break */
case 2 :
if ( e_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " enclosure must be a character " ) ;
RETURN_FALSE ;
}
enclosure = enclo [ 0 ] ;
/* no break */
case 1 :
if ( d_len ! = 1 ) {
php_error_docref ( NULL TSRMLS_CC , E_WARNING , " delimiter must be a character " ) ;
RETURN_FALSE ;
}
delimiter = delim [ 0 ] ;
/* no break */
case 0 :
break ;
2006-07-15 14:50:38 +00:00
}
intern - > u . file . delimiter = delimiter ;
intern - > u . file . enclosure = enclosure ;
2007-10-03 10:31:04 +00:00
intern - > u . file . escape = escape ;
2006-07-15 14:50:38 +00:00
}
}
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto array SplFileObject::getCsvControl() U
2006-07-15 14:50:38 +00:00
Get the delimiter and enclosure character used in fgetcsv */
SPL_METHOD ( SplFileObject , getCsvControl )
{
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
char delimiter [ 2 ] , enclosure [ 2 ] ;
array_init ( return_value ) ;
delimiter [ 0 ] = intern - > u . file . delimiter ;
delimiter [ 1 ] = ' \0 ' ;
enclosure [ 0 ] = intern - > u . file . enclosure ;
enclosure [ 1 ] = ' \0 ' ;
add_next_index_ascii_string ( return_value , delimiter , ZSTR_DUPLICATE ) ;
add_next_index_ascii_string ( return_value , enclosure , ZSTR_DUPLICATE ) ;
}
/* }}} */
2005-09-15 14:07:39 +00:00
/* {{{ proto bool SplFileObject::flock(int operation [, int &wouldblock])
2005-03-07 22:18:40 +00:00
Portable file locking */
FileFunction ( flock )
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileObject::fflush() U
2005-03-07 22:18:40 +00:00
Flush the file */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fflush )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
2005-10-08 15:55:04 +00:00
RETURN_BOOL ( ! php_stream_flush ( intern - > u . file . stream ) ) ;
2005-03-07 22:18:40 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::ftell() U
2005-03-07 22:18:40 +00:00
Return current file position */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , ftell )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
long ret = php_stream_tell ( intern - > u . file . stream ) ;
2005-03-07 22:18:40 +00:00
if ( ret = = - 1 ) {
RETURN_FALSE ;
} else {
RETURN_LONG ( ret ) ;
}
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::fseek(int pos [, int whence = SEEK_SET]) U
2005-03-07 22:18:40 +00:00
Return current file position */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fseek )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
long pos , whence = SEEK_SET ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l|l " , & pos , & whence ) = = FAILURE ) {
return ;
}
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
RETURN_LONG ( php_stream_seek ( intern - > u . file . stream , pos , whence ) ) ;
2005-03-07 22:18:40 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::fgetc() U
2005-03-07 22:18:40 +00:00
Get a character form the file */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fgetc )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
char buf [ 2 ] ;
int result ;
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
2005-05-03 22:18:19 +00:00
2005-10-08 15:55:04 +00:00
result = php_stream_getc ( intern - > u . file . stream ) ;
2005-03-07 22:18:40 +00:00
if ( result = = EOF ) {
RETVAL_FALSE ;
} else {
2005-05-03 22:18:19 +00:00
if ( result = = ' \n ' ) {
2005-10-08 15:55:04 +00:00
intern - > u . file . current_line_num + + ;
2005-05-03 22:18:19 +00:00
}
2005-03-07 22:18:40 +00:00
buf [ 0 ] = result ;
buf [ 1 ] = ' \0 ' ;
2007-01-17 21:29:38 +00:00
RETURN_RT_STRINGL ( buf , 1 , ZSTR_DUPLICATE ) ;
2005-03-07 22:18:40 +00:00
}
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto string SplFileObject::fgetss([string allowable_tags]) U
2005-03-07 22:18:40 +00:00
Get a line from file pointer and strip HTML tags */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fgetss )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
zval * arg2 = NULL ;
MAKE_STD_ZVAL ( arg2 ) ;
2008-06-18 10:05:15 +00:00
if ( intern - > u . file . max_line_len > 0 ) {
ZVAL_LONG ( arg2 , intern - > u . file . max_line_len ) ;
} else {
ZVAL_LONG ( arg2 , 1024 ) ;
}
2005-03-07 22:18:40 +00:00
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
intern - > u . file . current_line_num + + ;
2005-05-03 21:11:26 +00:00
2006-03-09 23:03:08 +00:00
FileFunctionCall ( fgetss , ZEND_NUM_ARGS ( ) , arg2 ) ;
2005-03-07 22:18:40 +00:00
zval_ptr_dtor ( & arg2 ) ;
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto int SplFileObject::fpassthru() U
2005-03-07 22:18:40 +00:00
Output all remaining data from a file pointer */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fpassthru )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
2005-10-08 15:55:04 +00:00
RETURN_LONG ( php_stream_passthru ( intern - > u . file . stream ) ) ;
2005-03-07 22:18:40 +00:00
} /* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileObject::fscanf(string format [, string ...]) U
2005-03-07 22:18:40 +00:00
Implements a mostly ANSI compatible fscanf ( ) */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fscanf )
2005-03-09 03:07:42 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-09 03:07:42 +00:00
2005-10-08 15:55:04 +00:00
spl_filesystem_file_free_line ( intern TSRMLS_CC ) ;
intern - > u . file . current_line_num + + ;
2005-03-09 03:07:42 +00:00
2006-03-09 23:03:08 +00:00
FileFunctionCall ( fscanf , ZEND_NUM_ARGS ( ) , NULL ) ;
2005-03-09 03:07:42 +00:00
}
2005-03-07 22:18:40 +00:00
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto mixed SplFileObject::fwrite(string str [, int length]) U
2005-03-07 22:18:40 +00:00
Binary - safe file write */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , fwrite )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
char * str ;
int str_len ;
2006-02-10 16:56:56 +00:00
long length = 0 ;
2005-03-07 22:18:40 +00:00
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " s|l " , & str , & str_len , & length ) = = FAILURE ) {
return ;
}
2006-02-10 16:56:56 +00:00
if ( ZEND_NUM_ARGS ( ) > 1 ) {
2005-03-07 22:18:40 +00:00
str_len = MAX ( 0 , MIN ( length , str_len ) ) ;
}
if ( ! str_len ) {
RETURN_LONG ( 0 ) ;
}
2005-10-08 15:55:04 +00:00
RETURN_LONG ( php_stream_write ( intern - > u . file . stream , str , str_len ) ) ;
2005-03-07 22:18:40 +00:00
} /* }}} */
2005-09-15 14:07:39 +00:00
/* {{{ proto bool SplFileObject::fstat()
2005-03-07 22:18:40 +00:00
Stat ( ) on a filehandle */
FileFunction ( fstat )
/* }}} */
2007-01-19 10:19:50 +00:00
/* {{{ proto bool SplFileObject::ftruncate(int size) U
2005-03-07 22:18:40 +00:00
Truncate file to ' size ' length */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , ftruncate )
2005-03-07 22:18:40 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-03-07 22:18:40 +00:00
long size ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & size ) = = FAILURE ) {
return ;
}
2005-10-08 15:55:04 +00:00
if ( ! php_stream_truncate_supported ( intern - > u . file . stream ) ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Can't truncate file %s " , intern - > file_name ) ;
2005-03-07 22:18:40 +00:00
RETURN_FALSE ;
}
2005-10-08 15:55:04 +00:00
RETURN_BOOL ( 0 = = php_stream_truncate_set_size ( intern - > u . file . stream , size ) ) ;
2005-03-07 22:18:40 +00:00
} /* }}} */
2005-09-15 14:07:39 +00:00
/* {{{ proto void SplFileObject::seek(int line_pos)
2005-05-03 21:11:26 +00:00
Seek to specified line */
2005-09-15 14:07:39 +00:00
SPL_METHOD ( SplFileObject , seek )
2005-05-03 21:11:26 +00:00
{
2005-10-08 15:55:04 +00:00
spl_filesystem_object * intern = ( spl_filesystem_object * ) zend_object_store_get_object ( getThis ( ) TSRMLS_CC ) ;
2005-05-03 21:11:26 +00:00
long line_pos ;
if ( zend_parse_parameters ( ZEND_NUM_ARGS ( ) TSRMLS_CC , " l " , & line_pos ) = = FAILURE ) {
return ;
}
if ( line_pos < 0 ) {
2006-02-13 10:23:59 +00:00
zend_throw_exception_ex ( spl_ce_LogicException , 0 TSRMLS_CC , " Can't seek file %s to negative line %ld " , intern - > file_name , line_pos ) ;
2005-05-03 21:11:26 +00:00
RETURN_FALSE ;
}
2006-03-09 23:03:08 +00:00
spl_filesystem_file_rewind ( getThis ( ) , intern TSRMLS_CC ) ;
2005-05-03 21:11:26 +00:00
2005-10-08 15:55:04 +00:00
while ( intern - > u . file . current_line_num < line_pos ) {
2008-09-11 15:31:48 +00:00
if ( spl_filesystem_file_read_line ( getThis ( ) , intern , 1 TSRMLS_CC ) = = FAILURE ) {
break ;
}
2005-05-03 21:11:26 +00:00
}
2005-11-27 12:13:42 +00:00
} /* }}} */
2005-05-03 21:11:26 +00:00
2005-11-27 12:13:42 +00:00
/* {{{ Function/Class/Method definitions */
2005-03-07 00:40:57 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object___construct , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , file_name )
ZEND_ARG_INFO ( 0 , open_mode )
ZEND_ARG_INFO ( 0 , use_include_path )
ZEND_ARG_INFO ( 0 , context )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-07 00:40:57 +00:00
2008-02-04 19:33:03 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_file_object_setFlags , 0 )
2005-03-07 00:40:57 +00:00
ZEND_ARG_INFO ( 0 , flags )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-07 00:40:57 +00:00
2008-02-04 19:33:03 +00:00
ZEND_BEGIN_ARG_INFO ( arginfo_file_object_setMaxLineLen , 0 )
2005-03-07 00:40:57 +00:00
ZEND_ARG_INFO ( 0 , max_len )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-07 00:40:57 +00:00
2008-02-04 19:33:03 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_fgetcsv , 0 , 0 , 0 )
2005-03-07 00:40:57 +00:00
ZEND_ARG_INFO ( 0 , delimiter )
ZEND_ARG_INFO ( 0 , enclosure )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-07 00:40:57 +00:00
2005-03-08 00:42:49 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_flock , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , operation )
2006-02-05 19:22:13 +00:00
ZEND_ARG_INFO ( 1 , wouldblock )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_fseek , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , pos )
ZEND_ARG_INFO ( 0 , whence )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_fgetss , 0 , 0 , 0 )
ZEND_ARG_INFO ( 0 , allowable_tags )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
2009-07-23 14:42:46 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_fscanf , 1 , 0 , 1 )
2005-03-08 00:42:49 +00:00
ZEND_ARG_INFO ( 0 , format )
2009-07-23 14:42:46 +00:00
ZEND_ARG_INFO ( 1 , . . . )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_fwrite , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , str )
ZEND_ARG_INFO ( 0 , length )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_ftruncate , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , size )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-03-08 00:42:49 +00:00
2005-05-03 21:11:26 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_file_object_seek , 0 , 0 , 1 )
ZEND_ARG_INFO ( 0 , line_pos )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-05-03 21:11:26 +00:00
2007-09-27 18:28:44 +00:00
static const zend_function_entry spl_SplFileObject_functions [ ] = {
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , __construct , arginfo_file_object___construct , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , rewind , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , eof , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , valid , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , fgets , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , fgetcsv , arginfo_file_object_fgetcsv , ZEND_ACC_PUBLIC )
2006-07-15 14:50:38 +00:00
SPL_ME ( SplFileObject , setCsvControl , arginfo_file_object_fgetcsv , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , getCsvControl , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , flock , arginfo_file_object_flock , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , fflush , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , ftell , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , fseek , arginfo_file_object_fseek , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , fgetc , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , fpassthru , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , fgetss , arginfo_file_object_fgetss , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , fscanf , arginfo_file_object_fscanf , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , fwrite , arginfo_file_object_fwrite , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , fstat , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , ftruncate , arginfo_file_object_ftruncate , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , current , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , key , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , next , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , setFlags , arginfo_file_object_setFlags , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , getFlags , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , setMaxLineLen , arginfo_file_object_setMaxLineLen , ZEND_ACC_PUBLIC )
2009-07-04 20:28:16 +00:00
SPL_ME ( SplFileObject , getMaxLineLen , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , hasChildren , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_ME ( SplFileObject , getChildren , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-09-15 14:07:39 +00:00
SPL_ME ( SplFileObject , seek , arginfo_file_object_seek , ZEND_ACC_PUBLIC )
2005-12-09 13:32:07 +00:00
/* mappings */
2009-07-04 20:28:16 +00:00
SPL_MA ( SplFileObject , getCurrentLine , SplFileObject , fgets , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
SPL_MA ( SplFileObject , __toString , SplFileObject , current , arginfo_splfileinfo_void , ZEND_ACC_PUBLIC )
2005-03-07 00:40:57 +00:00
{ NULL , NULL , NULL }
} ;
2003-12-13 14:40:56 +00:00
2006-09-29 12:28:57 +00:00
ZEND_BEGIN_ARG_INFO_EX ( arginfo_temp_file_object___construct , 0 , 0 , 0 )
2005-10-29 15:15:22 +00:00
ZEND_ARG_INFO ( 0 , max_memory )
2006-02-02 12:40:07 +00:00
ZEND_END_ARG_INFO ( )
2005-10-29 15:15:22 +00:00
2007-09-27 18:28:44 +00:00
static const zend_function_entry spl_SplTempFileObject_functions [ ] = {
2005-10-29 15:15:22 +00:00
SPL_ME ( SplTempFileObject , __construct , arginfo_temp_file_object___construct , ZEND_ACC_PUBLIC )
{ NULL , NULL , NULL }
} ;
2005-11-27 12:13:42 +00:00
/* }}} */
2005-10-29 15:15:22 +00:00
2003-11-09 14:05:36 +00:00
/* {{{ PHP_MINIT_FUNCTION(spl_directory)
*/
PHP_MINIT_FUNCTION ( spl_directory )
{
2008-02-02 22:53:05 +00:00
u_charsToUChars ( " glob:// " , u_glob , sizeof ( " glob:// " ) ) ;
2005-10-29 15:15:22 +00:00
REGISTER_SPL_STD_CLASS_EX ( SplFileInfo , spl_filesystem_object_new , spl_SplFileInfo_functions ) ;
2005-10-08 18:57:17 +00:00
memcpy ( & spl_filesystem_object_handlers , zend_get_std_object_handlers ( ) , sizeof ( zend_object_handlers ) ) ;
2008-07-19 11:20:04 +00:00
spl_filesystem_object_handlers . clone_obj = spl_filesystem_object_clone ;
spl_filesystem_object_handlers . cast_object = spl_filesystem_object_cast ;
2007-01-20 16:19:20 +00:00
spl_filesystem_object_handlers . get_debug_info = spl_filesystem_object_get_debug_info ;
2008-12-22 13:50:43 +00:00
spl_ce_SplFileInfo - > serialize = zend_class_serialize_deny ;
spl_ce_SplFileInfo - > unserialize = zend_class_unserialize_deny ;
2005-10-08 15:55:04 +00:00
2005-10-29 15:15:22 +00:00
REGISTER_SPL_SUB_CLASS_EX ( DirectoryIterator , SplFileInfo , spl_filesystem_object_new , spl_DirectoryIterator_functions ) ;
2003-11-09 14:05:36 +00:00
zend_class_implements ( spl_ce_DirectoryIterator TSRMLS_CC , 1 , zend_ce_iterator ) ;
2008-07-19 11:20:04 +00:00
REGISTER_SPL_IMPLEMENTS ( DirectoryIterator , SeekableIterator ) ;
2003-11-09 14:05:36 +00:00
2005-10-08 15:55:04 +00:00
spl_ce_DirectoryIterator - > get_iterator = spl_filesystem_dir_get_iterator ;
2003-11-09 14:05:36 +00:00
2008-02-02 22:53:05 +00:00
REGISTER_SPL_SUB_CLASS_EX ( FilesystemIterator , DirectoryIterator , spl_filesystem_object_new , spl_FilesystemIterator_functions ) ;
2005-11-27 13:07:18 +00:00
2008-02-02 22:53:05 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " CURRENT_MODE_MASK " , SPL_FILE_DIR_CURRENT_MODE_MASK ) ;
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " CURRENT_AS_PATHNAME " , SPL_FILE_DIR_CURRENT_AS_PATHNAME ) ;
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " CURRENT_AS_FILEINFO " , SPL_FILE_DIR_CURRENT_AS_FILEINFO ) ;
2008-02-04 19:33:03 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " CURRENT_AS_SELF " , SPL_FILE_DIR_CURRENT_AS_SELF ) ;
2008-02-02 22:53:05 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " KEY_MODE_MASK " , SPL_FILE_DIR_KEY_MODE_MASK ) ;
2008-02-04 19:33:03 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " KEY_AS_PATHNAME " , SPL_FILE_DIR_KEY_AS_PATHNAME ) ;
2009-07-08 03:09:58 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " FOLLOW_SYMLINKS " , SPL_FILE_DIR_FOLLOW_SYMLINKS ) ;
2008-02-02 22:53:05 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " KEY_AS_FILENAME " , SPL_FILE_DIR_KEY_AS_FILENAME ) ;
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " NEW_CURRENT_AND_KEY " , SPL_FILE_DIR_KEY_AS_FILENAME | SPL_FILE_DIR_CURRENT_AS_FILEINFO ) ;
2008-07-23 06:12:44 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " SKIP_DOTS " , SPL_FILE_DIR_SKIPDOTS ) ;
2008-07-24 08:52:24 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( FilesystemIterator , " UNIX_PATHS " , SPL_FILE_DIR_UNIXPATHS ) ;
2008-02-02 22:53:05 +00:00
spl_ce_FilesystemIterator - > get_iterator = spl_filesystem_tree_get_iterator ;
REGISTER_SPL_SUB_CLASS_EX ( RecursiveDirectoryIterator , FilesystemIterator , spl_filesystem_object_new , spl_RecursiveDirectoryIterator_functions ) ;
REGISTER_SPL_IMPLEMENTS ( RecursiveDirectoryIterator , RecursiveIterator ) ;
2003-11-09 14:05:36 +00:00
2008-02-02 22:53:05 +00:00
REGISTER_SPL_SUB_CLASS_EX ( GlobIterator , FilesystemIterator , spl_filesystem_object_new , spl_GlobIterator_functions ) ;
REGISTER_SPL_IMPLEMENTS ( GlobIterator , Countable ) ;
2003-11-09 14:05:36 +00:00
2005-10-29 15:15:22 +00:00
REGISTER_SPL_SUB_CLASS_EX ( SplFileObject , SplFileInfo , spl_filesystem_object_new , spl_SplFileObject_functions ) ;
2005-09-15 14:07:39 +00:00
REGISTER_SPL_IMPLEMENTS ( SplFileObject , RecursiveIterator ) ;
REGISTER_SPL_IMPLEMENTS ( SplFileObject , SeekableIterator ) ;
2005-03-07 00:40:57 +00:00
2005-09-15 14:07:39 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( SplFileObject , " DROP_NEW_LINE " , SPL_FILE_OBJECT_DROP_NEW_LINE ) ;
2006-03-09 23:03:08 +00:00
REGISTER_SPL_CLASS_CONST_LONG ( SplFileObject , " READ_AHEAD " , SPL_FILE_OBJECT_READ_AHEAD ) ;
REGISTER_SPL_CLASS_CONST_LONG ( SplFileObject , " SKIP_EMPTY " , SPL_FILE_OBJECT_SKIP_EMPTY ) ;
REGISTER_SPL_CLASS_CONST_LONG ( SplFileObject , " READ_CSV " , SPL_FILE_OBJECT_READ_CSV ) ;
2006-09-29 12:18:54 +00:00
REGISTER_SPL_SUB_CLASS_EX ( SplTempFileObject , SplFileObject , spl_filesystem_object_new , spl_SplTempFileObject_functions ) ;
2003-11-09 14:05:36 +00:00
return SUCCESS ;
}
/* }}} */
2003-07-16 15:13:23 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* End :
2003-11-09 14:05:36 +00:00
* vim600 : noet sw = 4 ts = 4 fdm = marker
* vim < 600 : noet sw = 4 ts = 4
2003-07-16 15:13:23 +00:00
*/