From 37c5ff40eaba8607d5a984dbd1cedb7ed11ba2db Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 27 Jul 2020 15:35:36 +0100 Subject: [PATCH] Add dedicated IO exceptions --- Zend/zend_exceptions.c | 3 ++ Zend/zend_exceptions.stub.php | 3 ++ Zend/zend_exceptions_arginfo.h | 18 ++++++- ...flectionExtension_getClassNames_basic.phpt | 18 ++++++- ext/standard/basic_functions.c | 3 ++ ext/standard/config.m4 | 2 +- ext/standard/config.w32 | 2 +- ext/standard/io_exceptions.c | 54 +++++++++++++++++++ ext/standard/io_exceptions.h | 32 +++++++++++ ext/standard/io_exceptions.stub.php | 14 +++++ ext/standard/io_exceptions_arginfo.h | 29 ++++++++++ 11 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 ext/standard/io_exceptions.c create mode 100644 ext/standard/io_exceptions.h create mode 100644 ext/standard/io_exceptions.stub.php create mode 100644 ext/standard/io_exceptions_arginfo.h diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index af71ac7a6589b..2557987bd82ae 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -42,6 +42,7 @@ ZEND_API zend_class_entry *zend_ce_value_error; ZEND_API zend_class_entry *zend_ce_arithmetic_error; ZEND_API zend_class_entry *zend_ce_division_by_zero_error; ZEND_API zend_class_entry *zend_ce_unhandled_match_error; +ZEND_API zend_class_entry *zend_ce_io; /* Internal pseudo-exception that is not exposed to userland. */ static zend_class_entry zend_ce_unwind_exit; @@ -791,6 +792,8 @@ void zend_register_default_exception(void) /* {{{ */ zend_ce_unhandled_match_error->create_object = zend_default_exception_new; INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL); + + zend_ce_io = register_class_IO(zend_ce_throwable); } /* }}} */ diff --git a/Zend/zend_exceptions.stub.php b/Zend/zend_exceptions.stub.php index 5f6a3a53e4e95..af7d52c5ce8ef 100644 --- a/Zend/zend_exceptions.stub.php +++ b/Zend/zend_exceptions.stub.php @@ -163,3 +163,6 @@ class DivisionByZeroError extends ArithmeticError class UnhandledMatchError extends Error { } + +interface IO extends Throwable {} + diff --git a/Zend/zend_exceptions_arginfo.h b/Zend/zend_exceptions_arginfo.h index b1e4844717763..eb66e31a2ffc0 100644 --- a/Zend/zend_exceptions_arginfo.h +++ b/Zend/zend_exceptions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: f322ba2ed3e636b6e99400edfbff98102b7e3d06 */ + * Stub hash: b987c82b0a663e3a8ef20c85362bb77d6612446d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -186,6 +186,11 @@ static const zend_function_entry class_UnhandledMatchError_methods[] = { ZEND_FE_END }; + +static const zend_function_entry class_IO_methods[] = { + ZEND_FE_END +}; + static zend_class_entry *register_class_Throwable(zend_class_entry *class_entry_Stringable) { zend_class_entry ce, *class_entry; @@ -394,3 +399,14 @@ static zend_class_entry *register_class_UnhandledMatchError(zend_class_entry *cl return class_entry; } + +static zend_class_entry *register_class_IO(zend_class_entry *class_entry_Throwable) +{ + zend_class_entry ce, *class_entry; + + INIT_CLASS_ENTRY(ce, "IO", class_IO_methods); + class_entry = zend_register_internal_interface(&ce); + zend_class_implements(class_entry, 1, class_entry_Throwable); + + return class_entry; +} diff --git a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt index 5c4d1cb87f1d7..d42bca9513076 100644 --- a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt @@ -8,13 +8,27 @@ $standard = new ReflectionExtension('standard'); var_dump($standard->getClassNames()); ?> --EXPECT-- -array(4) { +array(11) { [0]=> string(22) "__PHP_Incomplete_Class" [1]=> string(14) "AssertionError" [2]=> - string(15) "php_user_filter" + string(10) "FileSystem" [3]=> + string(7) "Network" + [4]=> + string(15) "FileSystemError" + [5]=> + string(12) "FileNotFound" + [6]=> + string(12) "NotDirectory" + [7]=> + string(23) "InsufficientPermissions" + [8]=> + string(16) "TemporaryFailure" + [9]=> + string(15) "php_user_filter" + [10]=> string(9) "Directory" } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 1a6326624ba2c..9afc3ce640702 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -30,6 +30,7 @@ #include "ext/session/php_session.h" #include "zend_exceptions.h" #include "zend_operators.h" +#include "io_exceptions.h" #include "ext/standard/php_dns.h" #include "ext/standard/php_uuencode.h" #include "ext/standard/php_mt_rand.h" @@ -346,6 +347,8 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ register_html_constants(INIT_FUNC_ARGS_PASSTHRU); register_string_constants(INIT_FUNC_ARGS_PASSTHRU); + BASIC_MINIT_SUBMODULE(io_exceptions) + BASIC_MINIT_SUBMODULE(var) BASIC_MINIT_SUBMODULE(file) BASIC_MINIT_SUBMODULE(pack) diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index d04add96298e9..f44aab66a72ac 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -440,7 +440,7 @@ PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32. http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \ filters.c proc_open.c streamsfuncs.c http.c password.c \ - random.c net.c hrtime.c crc32_x86.c,,, + random.c net.c hrtime.c crc32_x86.c io_exceptions.c,,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_ADD_MAKEFILE_FRAGMENT diff --git a/ext/standard/config.w32 b/ext/standard/config.w32 index 3de43d04c067e..605ea6f260fe5 100644 --- a/ext/standard/config.w32 +++ b/ext/standard/config.w32 @@ -35,7 +35,7 @@ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \ url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \ php_fopen_wrapper.c credits.c css.c var_unserializer.c ftok.c sha1.c \ user_filters.c uuencode.c filters.c proc_open.c password.c \ - streamsfuncs.c http.c flock_compat.c random.c hrtime.c", false /* never shared */, + streamsfuncs.c http.c flock_compat.c random.c hrtime.c io_exceptions.c", false /* never shared */, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); PHP_STANDARD = "yes"; ADD_MAKEFILE_FRAGMENT(); diff --git a/ext/standard/io_exceptions.c b/ext/standard/io_exceptions.c new file mode 100644 index 0000000000000..a86e9b4cbe5b7 --- /dev/null +++ b/ext/standard/io_exceptions.c @@ -0,0 +1,54 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | 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. | + +----------------------------------------------------------------------+ + | Authors: George Peter Banyard | + +----------------------------------------------------------------------+ + */ + +/* {{{ includes */ +#include "php.h" +#include "zend_exceptions.h" +#include "io_exceptions.h" +#include "io_exceptions_arginfo.h" + +/* Class entry pointers */ +PHPAPI zend_class_entry *zend_ce_filesystem; +PHPAPI zend_class_entry *zend_ce_network; +PHPAPI zend_class_entry *zend_ce_filesystem_error; +PHPAPI zend_class_entry *zend_ce_insufficient_permissions; +PHPAPI zend_class_entry *zend_ce_temporary_failure; + +PHP_MINIT_FUNCTION(io_exceptions) { + zend_class_entry ce; + + /* Register interfaces */ + INIT_CLASS_ENTRY(ce, "FileSystem", class_FileSystem_methods); + zend_ce_filesystem = zend_register_internal_interface(&ce); + + INIT_CLASS_ENTRY(ce, "Network", class_Network_methods); + zend_ce_network = zend_register_internal_interface(&ce); + + /* Register exceptions */ + INIT_CLASS_ENTRY(ce, "FileSystemError", class_FileSystemError_methods); + zend_ce_filesystem_error = zend_register_internal_class_ex(&ce, zend_ce_exception); + zend_class_implements(zend_ce_filesystem_error, 1, zend_ce_filesystem); + + INIT_CLASS_ENTRY(ce, "InsufficientPermissions", class_InsufficientPermissions_methods); + zend_ce_insufficient_permissions = zend_register_internal_class_ex(&ce, zend_ce_exception); + zend_class_implements(zend_ce_insufficient_permissions, 1, zend_ce_filesystem); + + INIT_CLASS_ENTRY(ce, "TemporaryFailure", class_TemporaryFailure_methods); + zend_ce_temporary_failure = zend_register_internal_class_ex(&ce, zend_ce_exception); + zend_class_implements(zend_ce_temporary_failure, 1, zend_ce_network); + + return SUCCESS; +} diff --git a/ext/standard/io_exceptions.h b/ext/standard/io_exceptions.h new file mode 100644 index 0000000000000..ab653b2253277 --- /dev/null +++ b/ext/standard/io_exceptions.h @@ -0,0 +1,32 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | 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. | + +----------------------------------------------------------------------+ + | Authors: George Peter Banyard | + +----------------------------------------------------------------------+ + */ + +#ifndef PHP_IO_EXCEPTION +#define PHP_IO_EXCEPTION + +PHP_MINIT_FUNCTION(io_exceptions); + +BEGIN_EXTERN_C() + +extern PHPAPI zend_class_entry *zend_ce_filesystem; +extern PHPAPI zend_class_entry *zend_ce_network; +extern PHPAPI zend_class_entry *zend_ce_filesystem_error; +extern PHPAPI zend_class_entry *zend_ce_insufficient_permissions; +extern PHPAPI zend_class_entry *zend_ce_temporary_failure; + +END_EXTERN_C() + +#endif /* PHP_IO_EXCEPTION */ diff --git a/ext/standard/io_exceptions.stub.php b/ext/standard/io_exceptions.stub.php new file mode 100644 index 0000000000000..8e93b24c66af9 --- /dev/null +++ b/ext/standard/io_exceptions.stub.php @@ -0,0 +1,14 @@ +