From 04aebae9e4255112057f65a0cebf72e44485f356 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sat, 4 Mar 2006 22:56:11 +0000 Subject: [PATCH] - Need to change a few things to exception based error handling - Drop erroneus/useless RecursiveDirectoryIterator::getSubPathInfo() --- ext/spl/spl.php | 11 ++------ ext/spl/spl_directory.c | 59 +++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 46 deletions(-) diff --git a/ext/spl/spl.php b/ext/spl/spl.php index 9f41df46c2..aa37e454d9 100755 --- a/ext/spl/spl.php +++ b/ext/spl/spl.php @@ -948,8 +948,8 @@ class SplFileInfo */ function setFileClass(string class_name = "SplFileObject") {/**/} - /** @param class_name name of class used with getFileInfo(), getPathInfo(), - * getSubPathInfo(). Must be derived from SplFileInfo. + /** @param class_name name of class used with getFileInfo(), getPathInfo(). + * Must be derived from SplFileInfo. */ function setInfoClass(string class_name = "SplFileInfo") {/**/} } @@ -1041,13 +1041,6 @@ class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveI /** @return the current sub path */ function getSubPathname() {/**/} - - /** @return SplFileInfo created for the current sub path - * @param class_name name of class to instantiate - * @see SplFileInfo::setInfoClass() - */ - function getSubPathInfo(string $class_name = NULL) {/**/} - } /** @ingroup SPL diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index e02ce2bf95..1f4f589133 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -748,26 +748,30 @@ SPL_METHOD(SplFileInfo, setFileClass) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = spl_ce_SplFileObject; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == FAILURE) { - return; + php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { + intern->file_class = ce; } - intern->file_class = ce; + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } /* }}} */ /* {{{ proto SplFileObject SplFileInfo::setInfoClass([string class_name]) - Class to use in getFileInfo(), getPathInfo(), getSubPathInfo() */ + Class to use in getFileInfo(), getPathInfo() */ SPL_METHOD(SplFileInfo, setInfoClass) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = spl_ce_SplFileInfo; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == FAILURE) { - return; + php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { + intern->info_class = ce; } - intern->info_class = ce; + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } /* }}} */ @@ -778,11 +782,13 @@ SPL_METHOD(SplFileInfo, getFileInfo) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = intern->info_class; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == FAILURE) { - return; + php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); + + 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); } - spl_filesystem_object_create_type(ht, intern, SPL_FS_INFO, ce, return_value TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } /* }}} */ @@ -793,11 +799,13 @@ SPL_METHOD(SplFileInfo, getPathInfo) spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); zend_class_entry *ce = intern->info_class; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == FAILURE) { - return; + php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { + spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC); } - spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); } /* }}} */ @@ -810,7 +818,7 @@ SPL_METHOD(RecursiveDirectoryIterator, __construct) int len; long flags = SPL_FILE_DIR_CURRENT_AS_FILEINFO; - php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); + php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &len, &flags) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); @@ -950,28 +958,6 @@ SPL_METHOD(RecursiveDirectoryIterator, getSubPathname) } /* }}} */ -/* {{{ proto SplFileInfo RecursiveDirectoryIterator::getSubPathInfo([string $class_info]) - Create SplFileInfo for sub path */ -SPL_METHOD(RecursiveDirectoryIterator, getSubPathInfo) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char *sub_name; - int len; - zend_class_entry *ce = intern->info_class; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == FAILURE) { - return; - } - - if (intern->u.dir.sub_path) { - len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name); - spl_filesystem_object_create_info(intern, sub_name, len, 0, ce, return_value TSRMLS_CC); - } else { - spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC); - } -} -/* }}} */ - /* define an overloaded iterator structure */ typedef struct { zend_object_iterator intern; @@ -1337,7 +1323,6 @@ static zend_function_entry spl_RecursiveDirectoryIterator_functions[] = { SPL_ME(RecursiveDirectoryIterator, getChildren, NULL, ZEND_ACC_PUBLIC) SPL_ME(RecursiveDirectoryIterator, getSubPath, NULL, ZEND_ACC_PUBLIC) SPL_ME(RecursiveDirectoryIterator, getSubPathname,NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, getSubPathInfo,arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; -- 2.40.0