xref: /PHP-7.4/ext/spl/spl_functions.h (revision 92ac598a)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) The PHP Group                                          |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Marcus Boerger <helly@php.net>                              |
16    +----------------------------------------------------------------------+
17  */
18 
19 #ifndef PHP_FUNCTIONS_H
20 #define PHP_FUNCTIONS_H
21 
22 #include "php.h"
23 
24 typedef zend_object* (*create_object_func_t)(zend_class_entry *class_type);
25 
26 #define REGISTER_SPL_STD_CLASS(class_name, obj_ctor) \
27 	spl_register_std_class(&spl_ce_ ## class_name, # class_name, obj_ctor, NULL);
28 
29 #define REGISTER_SPL_STD_CLASS_EX(class_name, obj_ctor, funcs) \
30 	spl_register_std_class(&spl_ce_ ## class_name, # class_name, obj_ctor, funcs);
31 
32 #define REGISTER_SPL_SUB_CLASS_EX(class_name, parent_class_name, obj_ctor, funcs) \
33 	spl_register_sub_class(&spl_ce_ ## class_name, spl_ce_ ## parent_class_name, # class_name, obj_ctor, funcs);
34 
35 #define REGISTER_SPL_INTERFACE(class_name) \
36 	spl_register_interface(&spl_ce_ ## class_name, # class_name, spl_funcs_ ## class_name);
37 
38 #define REGISTER_SPL_IMPLEMENTS(class_name, interface_name) \
39 	zend_class_implements(spl_ce_ ## class_name, 1, spl_ce_ ## interface_name);
40 
41 #define REGISTER_SPL_ITERATOR(class_name) \
42 	zend_class_implements(spl_ce_ ## class_name, 1, zend_ce_iterator);
43 
44 #define REGISTER_SPL_PROPERTY(class_name, prop_name, prop_flags) \
45 	spl_register_property(spl_ce_ ## class_name, prop_name, sizeof(prop_name)-1, prop_flags);
46 
47 #define REGISTER_SPL_CLASS_CONST_LONG(class_name, const_name, value) \
48 	zend_declare_class_constant_long(spl_ce_ ## class_name, const_name, sizeof(const_name)-1, (zend_long)value);
49 
50 void spl_register_std_class(zend_class_entry ** ppce, char * class_name, create_object_func_t ctor, const zend_function_entry * function_list);
51 void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, create_object_func_t ctor, const zend_function_entry * function_list);
52 void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry *functions);
53 
54 void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags);
55 
56 /* sub: whether to allow subclasses/interfaces
57    allow = 0: allow all classes and interfaces
58    allow > 0: allow all that match and mask ce_flags
59    allow < 0: disallow all that match and mask ce_flags
60  */
61 void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags);
62 void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags);
63 void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags);
64 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags);
65 
66 /* caller must efree(return) */
67 zend_string *spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len);
68 
69 #define SPL_ME(class_name, function_name, arg_info, flags) \
70 	PHP_ME( spl_ ## class_name, function_name, arg_info, flags)
71 
72 #define SPL_ABSTRACT_ME(class_name, function_name, arg_info) \
73 	ZEND_ABSTRACT_ME( spl_ ## class_name, function_name, arg_info)
74 
75 #define SPL_METHOD(class_name, function_name) \
76 	PHP_METHOD(spl_ ## class_name, function_name)
77 
78 #define SPL_MA(class_name, function_name, alias_class, alias_function, arg_info, flags) \
79 	PHP_MALIAS(spl_ ## alias_class, function_name, alias_function, arg_info, flags)
80 #endif /* PHP_FUNCTIONS_H */
81