mirror of
https://github.com/php/php-src.git
synced 2024-11-25 10:54:15 +08:00
- MFH Make this behave like in <= 5.2.5 and test for it
This commit is contained in:
parent
9feb21f5f1
commit
1d98b27235
@ -1030,8 +1030,8 @@ class DirectoryIterator extends SplFileInfo implements Iterator
|
||||
*/
|
||||
class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator
|
||||
{
|
||||
const CURRENT_AS_SELF 0x00000000; /* make RecursiveDirectoryTree::current() return getSelf() */
|
||||
const CURRENT_AS_FILEINFO 0x00000010; /* make RecursiveDirectoryTree::current() return SplFileInfo */
|
||||
const CURRENT_AS_FILEINFO 0x00000000; /* make RecursiveDirectoryTree::current() return SplFileInfo */
|
||||
const CURRENT_AS_SELF 0x00000010; /* make RecursiveDirectoryTree::current() return getSelf() */
|
||||
const CURRENT_AS_PATHNAME 0x00000020; /* make RecursiveDirectoryTree::current() return getPathname() */
|
||||
|
||||
const KEY_AS_PATHNAME 0x00000000; /* make RecursiveDirectoryTree::key() return getPathname() */
|
||||
|
@ -556,7 +556,7 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, int ctor_flag
|
||||
php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC);
|
||||
|
||||
if (ctor_flags & DIT_CTOR_FLAGS) {
|
||||
flags = 0;
|
||||
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
|
||||
parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &len, &flags);
|
||||
} else {
|
||||
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
|
||||
@ -1108,6 +1108,28 @@ SPL_METHOD(FilesystemIterator, next)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int FilesystemIterator::getFlags()
|
||||
Get handling flags */
|
||||
SPL_METHOD(FilesystemIterator, getFlags)
|
||||
{
|
||||
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
|
||||
RETURN_LONG(intern->flags);
|
||||
} /* }}} */
|
||||
|
||||
/* {{{ proto void FilesystemIterator::setFlags(long $flags)
|
||||
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);
|
||||
|
||||
intern->flags &= ~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK);
|
||||
intern->flags |= ((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK) & flags);
|
||||
} /* }}} */
|
||||
|
||||
/* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = false])
|
||||
Returns whether current entry is a directory and not '.' or '..' */
|
||||
SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
|
||||
@ -1575,12 +1597,19 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir_hasChildren, 0, 0, 0)
|
||||
ZEND_ARG_INFO(0, allow_links)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
static
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_r_dir_setFlags, 0, 0, 0)
|
||||
ZEND_ARG_INFO(0, flags)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
static const zend_function_entry spl_FilesystemIterator_functions[] = {
|
||||
SPL_ME(FilesystemIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, rewind, NULL, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, next, NULL, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, key, NULL, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, current, NULL, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, getFlags, NULL, ZEND_ACC_PUBLIC)
|
||||
SPL_ME(FilesystemIterator, setFlags, arginfo_r_dir_setFlags, ZEND_ACC_PUBLIC)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -116,8 +116,8 @@ static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_files
|
||||
#define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000006 /* skip empty lines */
|
||||
#define SPL_FILE_OBJECT_READ_CSV 0x00000008 /* read via fgetcsv */
|
||||
|
||||
#define SPL_FILE_DIR_CURRENT_AS_SELF 0x00000000 /* make RecursiveDirectoryTree::current() return getSelf() */
|
||||
#define SPL_FILE_DIR_CURRENT_AS_FILEINFO 0x00000010 /* make RecursiveDirectoryTree::current() return SplFileInfo */
|
||||
#define SPL_FILE_DIR_CURRENT_AS_FILEINFO 0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
|
||||
#define SPL_FILE_DIR_CURRENT_AS_SELF 0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
|
||||
#define SPL_FILE_DIR_CURRENT_AS_PATHNAME 0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */
|
||||
#define SPL_FILE_DIR_CURRENT_MODE_MASK 0x000000F0 /* mask RecursiveDirectoryTree::current() */
|
||||
#define SPL_FILE_DIR_CURRENT(intern,mode) ((intern->flags&SPL_FILE_DIR_CURRENT_MODE_MASK)==mode)
|
||||
|
77
ext/spl/tests/dit_002.phpt
Executable file
77
ext/spl/tests/dit_002.phpt
Executable file
@ -0,0 +1,77 @@
|
||||
--TEST--
|
||||
SPL: DirectoryIterator defaults
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("spl")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$classes = array(
|
||||
'DirectoryIterator' => 0,
|
||||
'FilesystemIterator' => 1,
|
||||
'RecursiveDirectoryIterator' => 1,
|
||||
'GlobIterator' => 1,
|
||||
);
|
||||
|
||||
foreach ($classes as $class => $flags) {
|
||||
echo "===$class===\n";
|
||||
$ref = new ReflectionClass($class);
|
||||
$obj = $ref->newInstance('glob://*');
|
||||
echo get_class($obj->current()) . "\n";
|
||||
if ($flags)
|
||||
{
|
||||
var_dump($obj->getFlags());
|
||||
$flags = array(
|
||||
FilesystemIterator::CURRENT_AS_FILEINFO => 0,
|
||||
FilesystemIterator::CURRENT_AS_SELF => 0,
|
||||
FilesystemIterator::CURRENT_AS_PATHNAME => 1,
|
||||
);
|
||||
foreach($flags as $flag => $isstring) {
|
||||
$obj->setFlags($flag);
|
||||
$obj->rewind();
|
||||
var_dump($obj->getFlags());
|
||||
if ($isstring) {
|
||||
$val = $obj->current();
|
||||
if (is_string($val)) {
|
||||
var_dump(true);
|
||||
} else {
|
||||
var_dump($val);
|
||||
}
|
||||
} else {
|
||||
echo get_class($obj->current()) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
===DirectoryIterator===
|
||||
DirectoryIterator
|
||||
===FilesystemIterator===
|
||||
SplFileInfo
|
||||
int(0)
|
||||
int(0)
|
||||
SplFileInfo
|
||||
int(16)
|
||||
FilesystemIterator
|
||||
int(32)
|
||||
bool(true)
|
||||
===RecursiveDirectoryIterator===
|
||||
SplFileInfo
|
||||
int(0)
|
||||
int(0)
|
||||
SplFileInfo
|
||||
int(16)
|
||||
RecursiveDirectoryIterator
|
||||
int(32)
|
||||
bool(true)
|
||||
===GlobIterator===
|
||||
SplFileInfo
|
||||
int(0)
|
||||
int(0)
|
||||
SplFileInfo
|
||||
int(16)
|
||||
GlobIterator
|
||||
int(32)
|
||||
bool(true)
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user