~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/spl/php_spl.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | PHP Version 5                                                        |
 
4
   +----------------------------------------------------------------------+
 
5
   | Copyright (c) 1997-2004 The PHP Group                                |
 
6
   +----------------------------------------------------------------------+
 
7
   | This source file is subject to version 3.0 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_0.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: php_spl.c,v 1.28.2.1 2005/08/24 10:18:15 johannes Exp $ */
 
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
#include "spl_functions.h"
 
30
#include "spl_engine.h"
 
31
#include "spl_array.h"
 
32
#include "spl_directory.h"
 
33
#include "spl_iterators.h"
 
34
#include "spl_sxe.h"
 
35
 
 
36
#ifdef COMPILE_DL_SPL
 
37
ZEND_GET_MODULE(spl)
 
38
#endif
 
39
 
 
40
ZEND_DECLARE_MODULE_GLOBALS(spl)
 
41
 
 
42
/* {{{ spl_functions
 
43
 */
 
44
function_entry spl_functions[] = {
 
45
        PHP_FE(spl_classes,             NULL)
 
46
        PHP_FE(class_parents,           NULL)
 
47
        PHP_FE(class_implements,        NULL)
 
48
        {NULL, NULL, NULL}
 
49
};
 
50
/* }}} */
 
51
 
 
52
/* {{{ spl_module_entry
 
53
 */
 
54
zend_module_entry spl_module_entry = {
 
55
        STANDARD_MODULE_HEADER,
 
56
        "SPL",
 
57
        spl_functions,
 
58
        PHP_MINIT(spl),
 
59
        PHP_MSHUTDOWN(spl),
 
60
        PHP_RINIT(spl),
 
61
        PHP_RSHUTDOWN(spl),
 
62
        PHP_MINFO(spl),
 
63
        "0.2",
 
64
        STANDARD_MODULE_PROPERTIES
 
65
};
 
66
/* }}} */
 
67
 
 
68
/* {{{ spl_functions_none
 
69
 */
 
70
function_entry spl_functions_none[] = {
 
71
        {NULL, NULL, NULL}
 
72
};
 
73
/* }}} */
 
74
 
 
75
/* {{{ spl_init_globals
 
76
 */
 
77
static void spl_init_globals(zend_spl_globals *spl_globals)
 
78
{
 
79
}
 
80
/* }}} */
 
81
 
 
82
/* {{{ PHP_MINIT_FUNCTION(spl)
 
83
 */
 
84
PHP_MINIT_FUNCTION(spl)
 
85
{
 
86
        ZEND_INIT_MODULE_GLOBALS(spl, spl_init_globals, NULL);
 
87
 
 
88
        PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU);
 
89
        PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU);
 
90
        PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU);
 
91
        PHP_MINIT(spl_sxe)(INIT_FUNC_ARGS_PASSTHRU);
 
92
 
 
93
        return SUCCESS;
 
94
}
 
95
/* }}} */
 
96
 
 
97
/* {{{ PHP_RINIT_FUNCTION(spl)
 
98
 */
 
99
PHP_RINIT_FUNCTION(spl)
 
100
{
 
101
        return SUCCESS;
 
102
}
 
103
/* }}} */
 
104
 
 
105
/* {{{ PHP_RSHUTDOWN_FUNCTION(spl)
 
106
 */
 
107
PHP_RSHUTDOWN_FUNCTION(spl)
 
108
{                      
 
109
        return SUCCESS;
 
110
}
 
111
/* }}} */
 
112
 
 
113
/* {{{ PHP_MSHUTDOWN_FUNCTION(spl)
 
114
 */
 
115
PHP_MSHUTDOWN_FUNCTION(spl)
 
116
{                      
 
117
        SPL_DEBUG(fprintf(stderr, "%s\n", "Shutting down SPL");)
 
118
 
 
119
        return SUCCESS;
 
120
}
 
121
/* }}} */
 
122
 
 
123
/* {{{ class_parents
 
124
 */
 
125
PHP_FUNCTION(class_parents)
 
126
{
 
127
        zval *obj;
 
128
        zend_class_entry *parent_class;
 
129
 
 
130
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
 
131
                RETURN_FALSE;
 
132
        }
 
133
        array_init(return_value);
 
134
        parent_class = Z_OBJCE_P(obj)->parent;
 
135
        while (parent_class) {
 
136
                spl_add_class_name(return_value, parent_class, 0, 0 TSRMLS_CC);
 
137
                parent_class = parent_class->parent;
 
138
        }
 
139
}
 
140
/* }}} */
 
141
 
 
142
/* {{{ class_implements
 
143
 */
 
144
PHP_FUNCTION(class_implements)
 
145
{
 
146
        zval *obj;
 
147
 
 
148
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) {
 
149
                RETURN_FALSE;
 
150
        }
 
151
        array_init(return_value);
 
152
        spl_add_interfaces(return_value, Z_OBJCE_P(obj), 1, ZEND_ACC_INTERFACE TSRMLS_CC);
 
153
}
 
154
/* }}} */
 
155
 
 
156
#define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
 
157
        spl_add_classes(&spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC)
 
158
 
 
159
#define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
 
160
        SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \
 
161
        SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \
 
162
        SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
 
163
        SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \
 
164
        SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
 
165
        SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
 
166
        SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \
 
167
        SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \
 
168
        SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \
 
169
        SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \
 
170
        SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \
 
171
        SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \
 
172
        SPL_ADD_CLASS(SimpleXMLIterator, z_list, sub, allow, ce_flags); \
 
173
 
 
174
/* {{{ spl_classes */
 
175
PHP_FUNCTION(spl_classes)
 
176
{
 
177
        array_init(return_value);
 
178
        
 
179
        SPL_LIST_CLASSES(return_value, 0, 0, 0)
 
180
}
 
181
/* }}} */
 
182
 
 
183
int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC)
 
184
{
 
185
        char *res;
 
186
        
 
187
        spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_PP(entry));
 
188
        efree(*list);
 
189
        *list = res;
 
190
        return ZEND_HASH_APPLY_KEEP;
 
191
}
 
192
 
 
193
/* {{{ PHP_MINFO(spl)
 
194
 */
 
195
PHP_MINFO_FUNCTION(spl)
 
196
{
 
197
        zval list;
 
198
        char *strg;
 
199
 
 
200
        php_info_print_table_start();
 
201
        php_info_print_table_header(2, "SPL support",        "enabled");
 
202
 
 
203
        INIT_PZVAL(&list);
 
204
        array_init(&list);
 
205
        SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE)
 
206
        strg = estrdup("");
 
207
        zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC);
 
208
        zval_dtor(&list);
 
209
        php_info_print_table_row(2, "Interfaces", strg + 2);
 
210
        efree(strg);
 
211
 
 
212
        INIT_PZVAL(&list);
 
213
        array_init(&list);
 
214
        SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE)
 
215
        strg = estrdup("");
 
216
        zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC);
 
217
        zval_dtor(&list);
 
218
        php_info_print_table_row(2, "Classes", strg + 2);
 
219
        efree(strg);
 
220
 
 
221
        php_info_print_table_end();
 
222
}
 
223
/* }}} */
 
224
 
 
225
/*
 
226
 * Local variables:
 
227
 * tab-width: 4
 
228
 * c-basic-offset: 4
 
229
 * End:
 
230
 * vim600: fdm=marker
 
231
 * vim: noet sw=4 ts=4
 
232
 */