Skip to content

Commit 95d2aa9

Browse files
committed
Add dedicated IO exceptions
1 parent 56efc79 commit 95d2aa9

10 files changed

+161
-8
lines changed

Zend/zend_exceptions.c

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ZEND_API zend_class_entry *zend_ce_value_error;
4141
ZEND_API zend_class_entry *zend_ce_arithmetic_error;
4242
ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
4343
ZEND_API zend_class_entry *zend_ce_unhandled_match_error;
44+
ZEND_API zend_class_entry *zend_ce_io;
4445

4546
/* Internal pseudo-exception that is not exposed to userland. */
4647
static zend_class_entry zend_ce_unwind_exit;
@@ -813,6 +814,9 @@ void zend_register_default_exception(void) /* {{{ */
813814
INIT_CLASS_ENTRY(ce, "UnhandledMatchError", NULL);
814815
zend_ce_unhandled_match_error = zend_register_internal_class_ex(&ce, zend_ce_error);
815816
zend_ce_unhandled_match_error->create_object = zend_default_exception_new;
817+
818+
INIT_CLASS_ENTRY(ce, "IO", class_IO_methods);
819+
zend_ce_io = zend_register_internal_interface(&ce);
816820
}
817821
/* }}} */
818822

Zend/zend_exceptions.stub.php

+2
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,5 @@ class ArithmeticError extends Error
119119
class DivisionByZeroError extends ArithmeticError
120120
{
121121
}
122+
123+
interface IO extends Throwable {}

Zend/zend_exceptions_arginfo.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7eb20393f4ca314324d9813983124f724189ce8a */
2+
* Stub hash: 7ced06621bcef27db8f911c656ac8b1c4b7b8cf3 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
55
ZEND_END_ARG_INFO()
@@ -179,3 +179,8 @@ static const zend_function_entry class_ArithmeticError_methods[] = {
179179
static const zend_function_entry class_DivisionByZeroError_methods[] = {
180180
ZEND_FE_END
181181
};
182+
183+
184+
static const zend_function_entry class_IO_methods[] = {
185+
ZEND_FE_END
186+
};

ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ Felix De Vliegher <[email protected]>
77
$standard = new ReflectionExtension('standard');
88
var_dump($standard->getClassNames());
99
?>
10-
--EXPECTF--
11-
array(4) {
10+
--EXPECT--
11+
array(9) {
1212
[0]=>
13-
%s(22) "__PHP_Incomplete_Class"
13+
string(22) "__PHP_Incomplete_Class"
1414
[1]=>
15-
%s(15) "php_user_filter"
15+
string(10) "FileSystem"
1616
[2]=>
17-
%s(9) "Directory"
17+
string(7) "Network"
1818
[3]=>
19-
%s(14) "AssertionError"
19+
string(15) "FileSystemError"
20+
[4]=>
21+
string(23) "InsufficientPermissions"
22+
[5]=>
23+
string(16) "TemporaryFailure"
24+
[6]=>
25+
string(15) "php_user_filter"
26+
[7]=>
27+
string(9) "Directory"
28+
[8]=>
29+
string(14) "AssertionError"
2030
}

ext/standard/basic_functions.c

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ext/session/php_session.h"
3131
#include "zend_exceptions.h"
3232
#include "zend_operators.h"
33+
#include "io_exceptions.h"
3334
#include "ext/standard/php_dns.h"
3435
#include "ext/standard/php_uuencode.h"
3536
#include "ext/standard/php_mt_rand.h"
@@ -345,6 +346,8 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */
345346
register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
346347
register_string_constants(INIT_FUNC_ARGS_PASSTHRU);
347348

349+
BASIC_MINIT_SUBMODULE(io_exceptions)
350+
348351
BASIC_MINIT_SUBMODULE(var)
349352
BASIC_MINIT_SUBMODULE(file)
350353
BASIC_MINIT_SUBMODULE(pack)

ext/standard/config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.
449449
http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
450450
var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \
451451
filters.c proc_open.c streamsfuncs.c http.c password.c \
452-
random.c net.c hrtime.c,,,
452+
random.c net.c hrtime.c io_exceptions.c,,,
453453
-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
454454

455455
PHP_ADD_MAKEFILE_FRAGMENT

ext/standard/io_exceptions.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: George Peter Banyard <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
/* {{{ includes */
18+
#include "php.h"
19+
#include "zend_exceptions.h"
20+
#include "io_exceptions.h"
21+
#include "io_exceptions_arginfo.h"
22+
23+
/* Class entry pointers */
24+
PHPAPI zend_class_entry *zend_ce_filesystem;
25+
PHPAPI zend_class_entry *zend_ce_network;
26+
PHPAPI zend_class_entry *zend_ce_filesystem_error;
27+
PHPAPI zend_class_entry *zend_ce_insufficient_permissions;
28+
PHPAPI zend_class_entry *zend_ce_temporary_failure;
29+
30+
PHP_MINIT_FUNCTION(io_exceptions) {
31+
zend_class_entry ce;
32+
33+
/* Register interfaces */
34+
INIT_CLASS_ENTRY(ce, "FileSystem", class_FileSystem_methods);
35+
zend_ce_filesystem = zend_register_internal_interface(&ce);
36+
37+
INIT_CLASS_ENTRY(ce, "Network", class_Network_methods);
38+
zend_ce_network = zend_register_internal_interface(&ce);
39+
40+
/* Register exceptions */
41+
INIT_CLASS_ENTRY(ce, "FileSystemError", class_FileSystemError_methods);
42+
zend_ce_filesystem_error = zend_register_internal_class_ex(&ce, zend_ce_exception);
43+
zend_class_implements(zend_ce_filesystem_error, 1, zend_ce_filesystem);
44+
45+
INIT_CLASS_ENTRY(ce, "InsufficientPermissions", class_InsufficientPermissions_methods);
46+
zend_ce_insufficient_permissions = zend_register_internal_class_ex(&ce, zend_ce_exception);
47+
zend_class_implements(zend_ce_insufficient_permissions, 1, zend_ce_filesystem);
48+
49+
INIT_CLASS_ENTRY(ce, "TemporaryFailure", class_TemporaryFailure_methods);
50+
zend_ce_temporary_failure = zend_register_internal_class_ex(&ce, zend_ce_exception);
51+
zend_class_implements(zend_ce_temporary_failure, 1, zend_ce_network);
52+
53+
return SUCCESS;
54+
}

ext/standard/io_exceptions.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: George Peter Banyard <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
#ifndef PHP_IO_EXCEPTION
18+
#define PHP_IO_EXCEPTION
19+
20+
PHP_MINIT_FUNCTION(io_exceptions);
21+
22+
BEGIN_EXTERN_C()
23+
24+
extern PHPAPI zend_class_entry *zend_ce_filesystem;
25+
extern PHPAPI zend_class_entry *zend_ce_network;
26+
extern PHPAPI zend_class_entry *zend_ce_filesystem_error;
27+
extern PHPAPI zend_class_entry *zend_ce_insufficient_permissions;
28+
extern PHPAPI zend_class_entry *zend_ce_temporary_failure;
29+
30+
END_EXTERN_C()
31+
32+
#endif /* PHP_IO_EXCEPTION */

ext/standard/io_exceptions.stub.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
interface FileSystem extends IO {}
6+
7+
interface Network extends IO {}
8+
9+
/* Should use more specialized ones instead but for PoC will use this instead */
10+
class FileSystemError extends Exception implements FileSystem {}
11+
12+
class InsufficientPermissions extends Exception implements FileSystem {}
13+
14+
class TemporaryFailure extends Exception implements Network {}

ext/standard/io_exceptions_arginfo.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 68880a94d8393c0d367cee9e9c18c8ac6d16d9f2 */
3+
4+
5+
6+
7+
static const zend_function_entry class_FileSystem_methods[] = {
8+
ZEND_FE_END
9+
};
10+
11+
12+
static const zend_function_entry class_Network_methods[] = {
13+
ZEND_FE_END
14+
};
15+
16+
17+
static const zend_function_entry class_FileSystemError_methods[] = {
18+
ZEND_FE_END
19+
};
20+
21+
22+
static const zend_function_entry class_InsufficientPermissions_methods[] = {
23+
ZEND_FE_END
24+
};
25+
26+
27+
static const zend_function_entry class_TemporaryFailure_methods[] = {
28+
ZEND_FE_END
29+
};

0 commit comments

Comments
 (0)