1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 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 : /* $Id: spl_functions.c 281094 2009-05-25 14:32:15Z felipe $ */
20 :
21 : #ifdef HAVE_CONFIG_H
22 : #include "config.h"
23 : #endif
24 :
25 : #include "php.h"
26 : #include "php_ini.h"
27 : #include "ext/standard/info.h"
28 : #include "php_spl.h"
29 :
30 : /* {{{ spl_register_interface */
31 : void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry * functions TSRMLS_DC)
32 102042 : {
33 : zend_class_entry ce;
34 :
35 102042 : INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), functions);
36 102042 : *ppce = zend_register_internal_interface(&ce TSRMLS_CC);
37 102042 : }
38 : /* }}} */
39 :
40 : /* {{{ spl_register_std_class */
41 : PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, const zend_function_entry * function_list TSRMLS_DC)
42 204084 : {
43 : zend_class_entry ce;
44 :
45 204084 : INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
46 204084 : *ppce = zend_register_internal_class(&ce TSRMLS_CC);
47 :
48 : /* entries changed by initialize */
49 204084 : if (obj_ctor) {
50 187077 : (*ppce)->create_object = obj_ctor;
51 : }
52 204084 : }
53 : /* }}} */
54 :
55 : /* {{{ spl_register_sub_class */
56 : 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 TSRMLS_DC)
57 612252 : {
58 : zend_class_entry ce;
59 :
60 612252 : INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
61 612252 : *ppce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
62 :
63 : /* entries changed by initialize */
64 612252 : if (obj_ctor) {
65 391161 : (*ppce)->create_object = obj_ctor;
66 : } else {
67 221091 : (*ppce)->create_object = parent_ce->create_object;
68 : }
69 612252 : }
70 : /* }}} */
71 :
72 : /* {{{ spl_register_property */
73 : void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC)
74 17007 : {
75 17007 : zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC);
76 17007 : }
77 : /* }}} */
78 :
79 : /* {{{ spl_add_class_name */
80 : void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
81 4737 : {
82 4737 : if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
83 2415 : size_t len = pce->name_length;
84 : zval *tmp;
85 :
86 2415 : if (zend_u_hash_find(Z_ARRVAL_P(list), IS_UNICODE, pce->name, len+1, (void*)&tmp) == FAILURE) {
87 2415 : MAKE_STD_ZVAL(tmp);
88 2415 : ZVAL_UNICODEL(tmp, pce->name.u, pce->name_length, 1);
89 2415 : zend_u_hash_add(Z_ARRVAL_P(list), IS_UNICODE, pce->name, len+1, &tmp, sizeof(zval *), NULL);
90 : }
91 : }
92 4737 : }
93 : /* }}} */
94 :
95 : /* {{{ spl_add_interfaces */
96 : void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
97 33 : {
98 : zend_uint num_interfaces;
99 :
100 64 : for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
101 31 : spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags TSRMLS_CC);
102 : }
103 33 : }
104 : /* }}} */
105 :
106 : /* {{{ spl_add_classes */
107 : int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
108 4698 : {
109 4698 : if (!pce) {
110 0 : return 0;
111 : }
112 4698 : spl_add_class_name(list, pce, allow, ce_flags TSRMLS_CC);
113 4698 : if (sub) {
114 0 : spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC);
115 0 : while (pce->parent) {
116 0 : pce = pce->parent;
117 0 : spl_add_classes(pce, list, sub, allow, ce_flags TSRMLS_CC);
118 : }
119 : }
120 4698 : return 0;
121 : }
122 : /* }}} */
123 :
124 : zstr spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len, int *name_len TSRMLS_DC) /* {{{ */
125 211 : {
126 : zstr rv;
127 : zstr zprop;
128 :
129 211 : zprop.u = zend_ascii_to_unicode(prop_name, prop_len + 1 ZEND_FILE_LINE_CC);
130 211 : zend_u_mangle_property_name(&rv, name_len, IS_UNICODE, ce->name, ce->name_length, zprop, prop_len, 0);
131 211 : efree(zprop.v);
132 211 : return rv;
133 : }
134 : /* }}} */
135 :
136 : /*
137 : * Local variables:
138 : * tab-width: 4
139 : * c-basic-offset: 4
140 : * End:
141 : * vim600: fdm=marker
142 : * vim: noet sw=4 ts=4
143 : */
|