Skip to content
Newer
Older
100755 445 lines (388 sloc) 13.6 KB
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
ccfc46b - Happy new year and PHP 5 for rest of the files too..
foobar authored Jan 8, 2004
5 | Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend 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.zend.com/license/2_00.txt. |
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Marcus Boerger <helly@php.net> |
16 +----------------------------------------------------------------------+
17 */
18
19 /* $Id$ */
20
21 #include "zend.h"
22 #include "zend_API.h"
23 #include "zend_interfaces.h"
24
1cc4a69 @smalyshev preserve ZEND_API in definition
smalyshev authored Mar 28, 2004
25 ZEND_API zend_class_entry *zend_ce_traversable;
26 ZEND_API zend_class_entry *zend_ce_aggregate;
27 ZEND_API zend_class_entry *zend_ce_iterator;
28 ZEND_API zend_class_entry *zend_ce_arrayaccess;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
29
30 /* {{{ zend_call_method
31 Only returns the returned zval if retval_ptr != NULL */
32 ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, char *function_name, int function_name_len, zval **retval_ptr_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC)
33 {
34 int result;
35 zend_fcall_info fci;
36 zval z_fname;
37 zval *retval;
38
39 zval **params[2];
40
41 params[0] = &arg1;
42 params[1] = &arg2;
43
44 fci.size = sizeof(fci);
45 /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
46 fci.object_pp = object_pp;
47 fci.function_name = &z_fname;
48 fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
49 fci.param_count = param_count;
50 fci.params = params;
51 fci.no_separation = 1;
52 fci.symbol_table = NULL;
53
54 if (!fn_proxy && !obj_ce) {
55 /* no interest in caching and no information already present that is
56 * needed later inside zend_call_function. */
57 ZVAL_STRINGL(&z_fname, function_name, function_name_len, 0);
58 result = zend_call_function(&fci, NULL TSRMLS_CC);
59 } else {
60 zend_fcall_info_cache fcic;
61
62 fcic.initialized = 1;
63 if (!obj_ce) {
64 obj_ce = Z_OBJCE_PP(object_pp);
65 }
66 if (!fn_proxy || !*fn_proxy) {
67 if (zend_hash_find(&obj_ce->function_table, function_name, function_name_len+1, (void **) &fcic.function_handler) == FAILURE) {
68 /* error at c-level */
69 zend_error(E_CORE_ERROR, "Couldn't find implementation for method %s::%s", obj_ce->name, function_name);
70 }
71 if (fn_proxy) {
72 *fn_proxy = fcic.function_handler;
73 }
74 } else {
75 fcic.function_handler = *fn_proxy;
76 }
77 fcic.calling_scope = obj_ce;
78 fcic.object_pp = object_pp;
79 result = zend_call_function(&fci, &fcic TSRMLS_CC);
80 }
81 if (result == FAILURE) {
82 /* error at c-level */
83 if (!obj_ce) {
84 obj_ce = Z_OBJCE_PP(object_pp);
85 }
86 zend_error(E_CORE_ERROR, "Couldn't execute method %s::%s", obj_ce->name, function_name);
87 }
88 if (!retval_ptr_ptr) {
89 if (retval) {
39df192 Correct destruction
Marcus Boerger authored Nov 17, 2003
90 zval_ptr_dtor(&retval);
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
91 }
92 return NULL;
93 }
94 return *retval_ptr_ptr;
95 }
96 /* }}} */
97
98 /* iterator interface, c-level functions used by engine */
99
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
100 /* {{{ zend_user_it_new_iterator */
101 static zval *zend_user_it_new_iterator(zend_class_entry *ce, zval *object TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
102 {
103 zval *retval;
104
105 return zend_call_method_with_0_params(&object, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
5824641 IteratorAggregate::getIterator() cannot return anythingy else than ob…
Marcus Boerger authored Nov 13, 2003
106
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
107 }
108 /* }}} */
109
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
110 /* {{{ zend_user_it_dtor */
e1cd098 - no unneccessary retval initialization
Marcus Boerger authored Apr 27, 2004
111 static void zend_user_it_invalidate_current(zend_object_iterator *_iter TSRMLS_DC)
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
112 {
113 zend_user_iterator *iter = (zend_user_iterator*)_iter;
114
115 if (iter->value) {
116 zval_ptr_dtor(&iter->value);
117 iter->value = NULL;
118 }
119 }
120 /* }}} */
121
122 /* {{{ zend_user_it_dtor */
123 static void zend_user_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
124 {
125 zend_user_iterator *iter = (zend_user_iterator*)_iter;
126 zval *object = (zval*)iter->it.data;
127
11ce65a - Fix warnings
Marcus Boerger authored Apr 27, 2004
128 zend_user_it_invalidate_current(_iter TSRMLS_CC);
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
129 zval_ptr_dtor(&object);
130 efree(iter);
131 }
132 /* }}} */
133
6b0f57e Rename hasMore() to valid() as discussed. (Part II)
Marcus Boerger authored Mar 8, 2004
134 /* {{{ zend_user_it_valid */
135 static int zend_user_it_valid(zend_object_iterator *_iter TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
136 {
f9d1309 Prevent some SEGV's when Exceptions are thorown inside iterators.
Marcus Boerger authored Nov 4, 2003
137 if (_iter) {
138 zend_user_iterator *iter = (zend_user_iterator*)_iter;
139 zval *object = (zval*)iter->it.data;
140 zval *more;
141 int result;
142
6b0f57e Rename hasMore() to valid() as discussed. (Part II)
Marcus Boerger authored Mar 8, 2004
143 zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_valid, "valid", &more);
f9d1309 Prevent some SEGV's when Exceptions are thorown inside iterators.
Marcus Boerger authored Nov 4, 2003
144 if (more) {
145 result = i_zend_is_true(more);
b29834a Use correct macro/function
Marcus Boerger authored Nov 18, 2003
146 zval_ptr_dtor(&more);
f9d1309 Prevent some SEGV's when Exceptions are thorown inside iterators.
Marcus Boerger authored Nov 4, 2003
147 return result ? SUCCESS : FAILURE;
148 }
149 }
150 return FAILURE;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
151 }
152 /* }}} */
153
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
154 /* {{{ zend_user_it_get_current_data */
155 static void zend_user_it_get_current_data(zend_object_iterator *_iter, zval ***data TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
156 {
157 zend_user_iterator *iter = (zend_user_iterator*)_iter;
158 zval *object = (zval*)iter->it.data;
159
160 if (!iter->value) {
161 zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_current, "current", &iter->value);
162 }
163 *data = &iter->value;
164 }
165 /* }}} */
166
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
167 /* {{{ zend_user_it_get_current_key_default */
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
168 #if 0
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
169 static int zend_user_it_get_current_key_default(zend_object_iterator *_iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
170 {
da6d68d Little iterator improvement: ability to store index in iterator
Marcus Boerger authored Nov 10, 2003
171 *int_key = _iter->index;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
172 return HASH_KEY_IS_LONG;
173 }
174 #endif
175 /* }}} */
176
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
177 /* {{{ zend_user_it_get_current_key */
178 static int zend_user_it_get_current_key(zend_object_iterator *_iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
179 {
180 zend_user_iterator *iter = (zend_user_iterator*)_iter;
181 zval *object = (zval*)iter->it.data;
182 zval *retval;
183
184 zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
185
c5abb9b Capture potential problem by error message
Marcus Boerger authored Apr 25, 2004
186 if (!retval) {
187 *int_key = 0;
188 zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name);
189 return HASH_KEY_IS_LONG;
190 }
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
191 switch (retval->type) {
192 default:
193 zend_error(E_WARNING, "Illegal type returned from %s::key()", iter->ce->name);
194 case IS_NULL:
195 *int_key = 0;
196 zval_ptr_dtor(&retval);
197 return HASH_KEY_IS_LONG;
198
199 case IS_STRING:
200 *str_key = estrndup(retval->value.str.val, retval->value.str.len);
201 *str_key_len = retval->value.str.len+1;
202 zval_ptr_dtor(&retval);
203 return HASH_KEY_IS_STRING;
204
205 case IS_DOUBLE:
206 case IS_RESOURCE:
207 case IS_BOOL:
208 case IS_LONG: {
209 if (retval->type == IS_DOUBLE) {
210 *int_key = (long)retval->value.dval;
211 } else {
212 *int_key = retval->value.lval;
213 }
214 }
215 zval_ptr_dtor(&retval);
216 return HASH_KEY_IS_LONG;
217 }
218 }
219 /* }}} */
220
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
221 /* {{{ zend_user_it_move_forward */
222 static void zend_user_it_move_forward(zend_object_iterator *_iter TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
223 {
224 zend_user_iterator *iter = (zend_user_iterator*)_iter;
225 zval *object = (zval*)iter->it.data;
226
11ce65a - Fix warnings
Marcus Boerger authored Apr 27, 2004
227 zend_user_it_invalidate_current(_iter TSRMLS_CC);
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
228 zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_next, "next", NULL);
229 }
230 /* }}} */
231
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
232 /* {{{ zend_user_it_rewind */
233 static void zend_user_it_rewind(zend_object_iterator *_iter TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
234 {
235 zend_user_iterator *iter = (zend_user_iterator*)_iter;
236 zval *object = (zval*)iter->it.data;
237
11ce65a - Fix warnings
Marcus Boerger authored Apr 27, 2004
238 zend_user_it_invalidate_current(_iter TSRMLS_CC);
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
239 zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_rewind, "rewind", NULL);
240 }
241 /* }}} */
242
243 zend_object_iterator_funcs zend_interface_iterator_funcs_iterator = {
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
244 zend_user_it_dtor,
6b0f57e Rename hasMore() to valid() as discussed. (Part II)
Marcus Boerger authored Mar 8, 2004
245 zend_user_it_valid,
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
246 zend_user_it_get_current_data,
247 zend_user_it_get_current_key,
248 zend_user_it_move_forward,
e1cd098 - no unneccessary retval initialization
Marcus Boerger authored Apr 27, 2004
249 zend_user_it_rewind,
250 zend_user_it_invalidate_current
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
251 };
252
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
253 /* {{{ zend_user_it_get_iterator */
254 static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
255 {
256 zend_user_iterator *iterator = emalloc(sizeof(zend_user_iterator));
257
258 object->refcount++;
259 iterator->it.data = (void*)object;
260 iterator->it.funcs = ce->iterator_funcs.funcs;
261 iterator->ce = Z_OBJCE_P(object);
262 iterator->value = NULL;
263 return (zend_object_iterator*)iterator;
264 }
265 /* }}} */
266
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
267 /* {{{ zend_user_it_get_new_iterator */
268 static zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object TSRMLS_DC)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
269 {
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
270 zval *iterator = zend_user_it_new_iterator(ce, object TSRMLS_CC);
c978cc2 Use correct order
Marcus Boerger authored Nov 18, 2003
271 zend_object_iterator *new_iterator;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
272
5206e9c - Allow getIterator() to fail
Marcus Boerger authored Jan 24, 2005
273 zend_class_entry *ce_it = iterator && Z_TYPE_P(iterator) == IS_OBJECT ? Z_OBJCE_P(iterator) : NULL;
5824641 IteratorAggregate::getIterator() cannot return anythingy else than ob…
Marcus Boerger authored Nov 13, 2003
274
4645502 @smalyshev quick fix for #29382
smalyshev authored Jul 26, 2004
275 if (!ce || !ce_it || !ce_it->get_iterator || (ce_it->get_iterator == zend_user_it_get_new_iterator && iterator == object)) {
5206e9c - Allow getIterator() to fail
Marcus Boerger authored Jan 24, 2005
276 if (!EG(exception))
277 {
278 zend_error(E_WARNING, "Objects returned by %s::getIterator() must be traversable or implement interface Iterator", ce->name);
279 }
280 if (iterator)
281 {
282 zval_ptr_dtor(&iterator);
283 }
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
284 return NULL;
285 }
c978cc2 Use correct order
Marcus Boerger authored Nov 18, 2003
286 new_iterator = ce_it->get_iterator(ce_it, iterator TSRMLS_CC);
287 zval_ptr_dtor(&iterator);
288 return new_iterator;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
289 }
290 /* }}} */
291
292 /* {{{ zend_implement_traversable */
293 static int zend_implement_traversable(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
294 {
295 /* check that class_type is traversable at c-level or implements at least one of 'aggregate' and 'Iterator' */
01af2c3 Fix warnign
Marcus Boerger authored Sep 27, 2004
296 zend_uint i;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
297
64c7645 #where has my bracket been gone?
Marcus Boerger authored Jan 17, 2004
298 if (class_type->get_iterator || (class_type->parent && class_type->parent->get_iterator)) {
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
299 return SUCCESS;
50ee116 Clearify the different method/class flags (as discussed with Andi).
Marcus Boerger authored Mar 9, 2004
300 }
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
301 for (i = 0; i < class_type->num_interfaces; i++) {
302 if (class_type->interfaces[i] == zend_ce_aggregate || class_type->interfaces[i] == zend_ce_iterator) {
303 return SUCCESS;
304 }
305 }
306 zend_error(E_CORE_ERROR, "Class %s must implement interface %s as part of either %s or %s",
307 class_type->name,
308 zend_ce_traversable->name,
309 zend_ce_iterator->name,
310 zend_ce_aggregate->name);
311 return FAILURE;
312 }
313 /* }}} */
314
315 /* {{{ zend_implement_aggregate */
316 static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
317 {
851a02e Give some freedon to c iterators but not in userspace.
Marcus Boerger authored Oct 28, 2003
318 if (class_type->get_iterator) {
319 if (class_type->type == ZEND_INTERNAL_CLASS) {
320 /* inheritance ensures the class has necessary userland methods */
321 return SUCCESS;
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
322 } else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
851a02e Give some freedon to c iterators but not in userspace.
Marcus Boerger authored Oct 28, 2003
323 /* c-level get_iterator cannot be changed */
324 return FAILURE;
325 }
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
326 }
327 class_type->iterator_funcs.zf_new_iterator = NULL;
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
328 class_type->get_iterator = zend_user_it_get_new_iterator;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
329 return SUCCESS;
330 }
331 /* }}} */
332
333 /* {{{ zend_implement_iterator */
334 static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
335 {
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
336 if (class_type->get_iterator && class_type->get_iterator != zend_user_it_get_iterator) {
851a02e Give some freedon to c iterators but not in userspace.
Marcus Boerger authored Oct 28, 2003
337 if (class_type->type == ZEND_INTERNAL_CLASS) {
338 /* inheritance ensures the class has the necessary userland methods */
339 return SUCCESS;
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
340 } else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
851a02e Give some freedon to c iterators but not in userspace.
Marcus Boerger authored Oct 28, 2003
341 /* c-level get_iterator cannot be changed */
342 return FAILURE;
343 }
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
344 }
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
345 class_type->get_iterator = zend_user_it_get_iterator;
6b0f57e Rename hasMore() to valid() as discussed. (Part II)
Marcus Boerger authored Mar 8, 2004
346 class_type->iterator_funcs.zf_valid = NULL;
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
347 class_type->iterator_funcs.zf_current = NULL;
348 class_type->iterator_funcs.zf_key = NULL;
349 class_type->iterator_funcs.zf_next = NULL;
350 class_type->iterator_funcs.zf_rewind = NULL;
351 if (!class_type->iterator_funcs.funcs) {
352 class_type->iterator_funcs.funcs = &zend_interface_iterator_funcs_iterator;
353 }
354 return SUCCESS;
355 }
356 /* }}} */
357
4dba05d Add new interface ArrayAccess to use objects as Arrays
Marcus Boerger authored Nov 24, 2003
358 /* {{{ zend_implement_arrayaccess */
359 static int zend_implement_arrayaccess(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC)
360 {
6186617 - Export struct zend_user_iterator
Marcus Boerger authored Jan 26, 2004
361 #if 0
362 /* get ht from ce */
363 if (ht->read_dimension != zend_std_read_dimension
364 || ht->write_dimension != zend_std_write_dimension
365 || ht->has_dimension != zend_std_has_dimension
366 || ht->unset_dimension != zend_std_unset_dimension) {
367 return FAILURE;
368 }
369 #endif
4dba05d Add new interface ArrayAccess to use objects as Arrays
Marcus Boerger authored Nov 24, 2003
370 return SUCCESS;
371 }
372 /* }}}*/
373
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
374 /* {{{ function tables */
375 zend_function_entry zend_funcs_aggregate[] = {
376 ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
377 {NULL, NULL, NULL}
378 };
379
380 zend_function_entry zend_funcs_iterator[] = {
381 ZEND_ABSTRACT_ME(iterator, current, NULL)
382 ZEND_ABSTRACT_ME(iterator, next, NULL)
383 ZEND_ABSTRACT_ME(iterator, key, NULL)
b6b7c9e Rename hasMore() to valid() as discussed. (Part I)
Marcus Boerger authored Mar 8, 2004
384 ZEND_ABSTRACT_ME(iterator, valid, NULL)
da6d68d Little iterator improvement: ability to store index in iterator
Marcus Boerger authored Nov 10, 2003
385 ZEND_ABSTRACT_ME(iterator, rewind, NULL)
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
386 {NULL, NULL, NULL}
387 };
388
389 zend_function_entry *zend_funcs_traversable = NULL;
4dba05d Add new interface ArrayAccess to use objects as Arrays
Marcus Boerger authored Nov 24, 2003
390
391 static
e7e0f7d @zsuraski - Check return-by-reference bit when implementing interface prototypes
zsuraski authored Feb 12, 2004
392 ZEND_BEGIN_ARG_INFO(arginfo_arrayaccess_offset, 0)
4dba05d Add new interface ArrayAccess to use objects as Arrays
Marcus Boerger authored Nov 24, 2003
393 ZEND_ARG_INFO(0, offset)
394 ZEND_END_ARG_INFO();
395
396 static
397 ZEND_BEGIN_ARG_INFO(arginfo_arrayaccess_offset_value, 0)
398 ZEND_ARG_INFO(0, offset)
399 ZEND_ARG_INFO(0, value)
400 ZEND_END_ARG_INFO();
401
402 zend_function_entry zend_funcs_arrayaccess[] = {
403 ZEND_ABSTRACT_ME(arrayaccess, offsetExists, arginfo_arrayaccess_offset)
404 ZEND_ABSTRACT_ME(arrayaccess, offsetGet, arginfo_arrayaccess_offset)
405 ZEND_ABSTRACT_ME(arrayaccess, offsetSet, arginfo_arrayaccess_offset_value)
406 ZEND_ABSTRACT_ME(arrayaccess, offsetUnset, arginfo_arrayaccess_offset)
407 {NULL, NULL, NULL}
408 };
409
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
410 /* }}} */
411
412 #define REGISTER_ITERATOR_INTERFACE(class_name, class_name_str) \
413 {\
414 zend_class_entry ce;\
415 INIT_CLASS_ENTRY(ce, # class_name_str, zend_funcs_ ## class_name) \
416 zend_ce_ ## class_name = zend_register_internal_interface(&ce TSRMLS_CC);\
417 zend_ce_ ## class_name->interface_gets_implemented = zend_implement_ ## class_name;\
418 }
419
420 #define REGISTER_ITERATOR_IMPLEMENT(class_name, interface_name) \
421 zend_class_implements(zend_ce_ ## class_name TSRMLS_CC, 1, zend_ce_ ## interface_name)
422
423 /* {{{ zend_register_interfaces */
424 ZEND_API void zend_register_interfaces(TSRMLS_D)
425 {
426 REGISTER_ITERATOR_INTERFACE(traversable, Traversable);
427
428 REGISTER_ITERATOR_INTERFACE(aggregate, IteratorAggregate);
429 REGISTER_ITERATOR_IMPLEMENT(aggregate, traversable);
430
431 REGISTER_ITERATOR_INTERFACE(iterator, Iterator);
432 REGISTER_ITERATOR_IMPLEMENT(iterator, traversable);
4dba05d Add new interface ArrayAccess to use objects as Arrays
Marcus Boerger authored Nov 24, 2003
433
434 REGISTER_ITERATOR_INTERFACE(arrayaccess, ArrayAccess);
8abb3bd Impement userspace iterator interfaces and tests. See tests for details
Marcus Boerger authored Oct 22, 2003
435 }
436 /* }}} */
437
438 /*
439 * Local variables:
440 * tab-width: 4
441 * c-basic-offset: 4
442 * indent-tabs-mode: t
443 * End:
444 */
Something went wrong with that request. Please try again.