1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2018 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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "php.h"
24 #include "php_ini.h"
25 #include "ext/standard/info.h"
26 #include "php_spl.h"
27
28 /* {{{ spl_register_interface */
spl_register_interface(zend_class_entry ** ppce,char * class_name,const zend_function_entry * functions)29 void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry * functions)
30 {
31 zend_class_entry ce;
32
33 INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), functions);
34 *ppce = zend_register_internal_interface(&ce);
35 }
36 /* }}} */
37
38 /* {{{ spl_register_std_class */
spl_register_std_class(zend_class_entry ** ppce,char * class_name,void * obj_ctor,const zend_function_entry * function_list)39 PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, const zend_function_entry * function_list)
40 {
41 zend_class_entry ce;
42
43 INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
44 *ppce = zend_register_internal_class(&ce);
45
46 /* entries changed by initialize */
47 if (obj_ctor) {
48 (*ppce)->create_object = obj_ctor;
49 }
50 }
51 /* }}} */
52
53 /* {{{ spl_register_sub_class */
spl_register_sub_class(zend_class_entry ** ppce,zend_class_entry * parent_ce,char * class_name,void * obj_ctor,const zend_function_entry * function_list)54 PHPAPI void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, void *obj_ctor, const zend_function_entry * function_list)
55 {
56 zend_class_entry ce;
57
58 INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
59 *ppce = zend_register_internal_class_ex(&ce, parent_ce);
60
61 /* entries changed by initialize */
62 if (obj_ctor) {
63 (*ppce)->create_object = obj_ctor;
64 } else {
65 (*ppce)->create_object = parent_ce->create_object;
66 }
67 }
68 /* }}} */
69
70 /* {{{ spl_register_property */
spl_register_property(zend_class_entry * class_entry,char * prop_name,int prop_name_len,int prop_flags)71 void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags)
72 {
73 zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags);
74 }
75 /* }}} */
76
77 /* {{{ spl_add_class_name */
spl_add_class_name(zval * list,zend_class_entry * pce,int allow,int ce_flags)78 void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
79 {
80 if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
81 zval *tmp;
82
83 if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
84 zval t;
85 ZVAL_STR_COPY(&t, pce->name);
86 zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
87 }
88 }
89 }
90 /* }}} */
91
92 /* {{{ spl_add_interfaces */
spl_add_interfaces(zval * list,zend_class_entry * pce,int allow,int ce_flags)93 void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
94 {
95 uint32_t num_interfaces;
96
97 for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
98 spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
99 }
100 }
101 /* }}} */
102
103 /* {{{ spl_add_traits */
spl_add_traits(zval * list,zend_class_entry * pce,int allow,int ce_flags)104 void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
105 {
106 uint32_t num_traits;
107
108 for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
109 spl_add_class_name(list, pce->traits[num_traits], allow, ce_flags);
110 }
111 }
112 /* }}} */
113
114
115 /* {{{ spl_add_classes */
spl_add_classes(zend_class_entry * pce,zval * list,int sub,int allow,int ce_flags)116 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags)
117 {
118 if (!pce) {
119 return 0;
120 }
121 spl_add_class_name(list, pce, allow, ce_flags);
122 if (sub) {
123 spl_add_interfaces(list, pce, allow, ce_flags);
124 while (pce->parent) {
125 pce = pce->parent;
126 spl_add_classes(pce, list, sub, allow, ce_flags);
127 }
128 }
129 return 0;
130 }
131 /* }}} */
132
spl_gen_private_prop_name(zend_class_entry * ce,char * prop_name,int prop_len)133 zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
134 {
135 return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
136 }
137 /* }}} */
138
139 /*
140 * Local variables:
141 * tab-width: 4
142 * c-basic-offset: 4
143 * End:
144 * vim600: fdm=marker
145 * vim: noet sw=4 ts=4
146 */
147