1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
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 272374 2008-12-31 11:17:49Z sebastian $ */
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_destroy_class */
31 : void spl_destroy_class(zend_class_entry ** ppce)
32 0 : {
33 : SPL_DEBUG(fprintf(stderr, "Destroy(%s): %s\n", (*ppce)->type == ZEND_USER_CLASS ? "user" : "other", (*ppce)->name);)
34 0 : destroy_zend_class(ppce);
35 0 : }
36 : /* }}} */
37 :
38 : /* {{{ spl_register_interface */
39 : void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry * functions TSRMLS_DC)
40 81390 : {
41 : zend_class_entry ce;
42 :
43 81390 : INIT_CLASS_ENTRY(ce, class_name, functions);
44 81390 : ce.name_length = strlen(class_name);
45 81390 : *ppce = zend_register_internal_interface(&ce TSRMLS_CC);
46 81390 : }
47 : /* }}} */
48 :
49 : /* {{{ spl_register_std_class */
50 : PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, zend_function_entry * function_list TSRMLS_DC)
51 94955 : {
52 : zend_class_entry ce;
53 :
54 94955 : INIT_CLASS_ENTRY(ce, class_name, function_list);
55 94955 : ce.name_length = strlen(class_name);
56 94955 : *ppce = zend_register_internal_class(&ce TSRMLS_CC);
57 :
58 : /* entries changed by initialize */
59 94955 : if (obj_ctor) {
60 81390 : (*ppce)->create_object = obj_ctor;
61 : }
62 94955 : }
63 : /* }}} */
64 :
65 : /* {{{ spl_register_sub_class */
66 : PHPAPI void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, void *obj_ctor, zend_function_entry * function_list TSRMLS_DC)
67 406950 : {
68 : zend_class_entry ce;
69 :
70 406950 : INIT_CLASS_ENTRY(ce, class_name, function_list);
71 406950 : ce.name_length = strlen(class_name);
72 406950 : *ppce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
73 :
74 : /* entries changed by initialize */
75 406950 : if (obj_ctor) {
76 230605 : (*ppce)->create_object = obj_ctor;
77 : } else {
78 176345 : (*ppce)->create_object = parent_ce->create_object;
79 : }
80 406950 : }
81 : /* }}} */
82 :
83 : /* {{{ spl_register_parent_ce */
84 : void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC)
85 0 : {
86 0 : class_entry->parent = parent_class;
87 0 : }
88 : /* }}} */
89 :
90 : /* {{{ spl_register_functions */
91 : void spl_register_functions(zend_class_entry * class_entry, zend_function_entry * function_list TSRMLS_DC)
92 0 : {
93 0 : zend_register_functions(class_entry, function_list, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC);
94 0 : }
95 : /* }}} */
96 :
97 : /* {{{ spl_register_property */
98 : void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC)
99 13565 : {
100 13565 : zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC);
101 13565 : }
102 : /* }}} */
103 :
104 : /* {{{ spl_add_class_name */
105 : void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
106 598 : {
107 598 : if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
108 340 : size_t len = strlen(pce->name);
109 : zval *tmp;
110 :
111 340 : if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) {
112 340 : MAKE_STD_ZVAL(tmp);
113 340 : ZVAL_STRING(tmp, pce->name, 1);
114 340 : zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL);
115 : }
116 : }
117 598 : }
118 : /* }}} */
119 :
120 : /* {{{ spl_add_interfaces */
121 : void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
122 33 : {
123 : zend_uint num_interfaces;
124 :
125 64 : for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
126 31 : spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags TSRMLS_CC);
127 : }
128 33 : }
129 : /* }}} */
130 :
131 : /* {{{ spl_add_classes */
132 : int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
133 559 : {
134 559 : zend_class_entry *pce = *ppce;
135 :
136 559 : if (!pce) {
137 0 : return 0;
138 : }
139 559 : spl_add_class_name(list, pce, allow, ce_flags TSRMLS_CC);
140 559 : if (sub) {
141 0 : spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC);
142 0 : while (pce->parent) {
143 0 : pce = pce->parent;
144 0 : spl_add_classes(&pce, list, sub, allow, ce_flags TSRMLS_CC);
145 : }
146 : }
147 559 : return 0;
148 : }
149 : /* }}} */
150 :
151 : /*
152 : * Local variables:
153 : * tab-width: 4
154 : * c-basic-offset: 4
155 : * End:
156 : * vim600: fdm=marker
157 : * vim: noet sw=4 ts=4
158 : */
|