diff options
author | Marcus Boerger <helly@php.net> | 2004-11-01 00:26:59 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2004-11-01 00:26:59 +0000 |
commit | b9470609ad6ccb27ec38c8dd1fdbe121a41f33b5 (patch) | |
tree | 77ed6faf25981c04b8fa5ec03cd07a6a6888b6e2 /ext/spl | |
parent | 9626e9859a045d76f4fdd339c61d9c4345758f68 (diff) | |
download | php-git-b9470609ad6ccb27ec38c8dd1fdbe121a41f33b5.tar.gz |
- Minor fixes
- Implement AppendIterator in C
Diffstat (limited to 'ext/spl')
-rwxr-xr-x | ext/spl/examples/tests/examples.inc | 4 | ||||
-rwxr-xr-x | ext/spl/internal/appenditerator.inc (renamed from ext/spl/examples/appenditerator.inc) | 9 | ||||
-rwxr-xr-x | ext/spl/php_spl.c | 1 | ||||
-rwxr-xr-x | ext/spl/spl_array.c | 27 | ||||
-rwxr-xr-x | ext/spl/spl_array.h | 2 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.c | 213 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.h | 6 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_001.phpt | 39 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_007.phpt | 30 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_010.phpt | 18 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_011.phpt | 51 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_012.phpt | 33 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_013.phpt | 66 |
13 files changed, 442 insertions, 57 deletions
diff --git a/ext/spl/examples/tests/examples.inc b/ext/spl/examples/tests/examples.inc index 74b652adb5..feeba7db24 100755 --- a/ext/spl/examples/tests/examples.inc +++ b/ext/spl/examples/tests/examples.inc @@ -13,10 +13,6 @@ class IncludeFiles extends ArrayIterator } $classes = array( - 'EmptyIterator', - 'InfiniteIterator', - 'AppendIterator', - 'NoRewindIterator', ); foreach (new IncludeFiles(dirname(__FILE__). '/..', $classes) as $file) diff --git a/ext/spl/examples/appenditerator.inc b/ext/spl/internal/appenditerator.inc index d9edebc123..256d4cc22b 100755 --- a/ext/spl/examples/appenditerator.inc +++ b/ext/spl/internal/appenditerator.inc @@ -1,7 +1,7 @@ <?php /** @file appenditerator.inc - * @ingroup Examples + * @ingroup SPL * @brief class AppendIterator * @author Marcus Boerger * @date 2003 - 2004 @@ -9,7 +9,7 @@ * SPL - Standard PHP Library */ -/** @ingroup Examples +/** @ingroup SPL * @brief Iterator that iterates over several iterators one after the other * @author Marcus Boerger * @version 1.0 @@ -28,6 +28,11 @@ class AppendIterator implements OuterIterator /** Append an Iterator * @param $it Iterator to append + * + * If the current state is invalid but the appended iterator is valid + * the the AppendIterator itself becomes valid. However there will be no + * call to $it->rewind(). Also if the current state is invalid the inner + * ArrayIterator will be rewound und forwarded to the appended element. */ function append(Iterator $it) { diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index f4bfb7d874..c3f6b7599b 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -161,6 +161,7 @@ PHP_FUNCTION(class_implements) spl_add_classes(&spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC) #define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \ + SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \ diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 73ebfbf195..f68fbef31c 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -371,20 +371,12 @@ SPL_METHOD(Array, offsetSet) spl_array_write_dimension(getThis(), index, value TSRMLS_CC); } /* }}} */ -/* {{{ proto void ArrayObject::append(mixed $newval) - proto void ArrayIterator::append(mixed $newval) - Appends the value (cannot be called for objects). */ -SPL_METHOD(Array, append) + +void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /* {{{ */ { - zval *object = getThis(); spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); HashTable *aht = HASH_OF(intern->array); - zval *value; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { - return; - } - if (!aht) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); return; @@ -394,12 +386,25 @@ SPL_METHOD(Array, append) php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot append properties to objects, use %s::offsetSet() instead", Z_OBJCE_P(object)->name); } - spl_array_write_dimension(object, NULL, value TSRMLS_CC); + spl_array_write_dimension(object, NULL, append_value TSRMLS_CC); if (!intern->pos) { intern->pos = aht->pListTail; } } /* }}} */ +/* {{{ proto void ArrayObject::append(mixed $newval) + proto void ArrayIterator::append(mixed $newval) + Appends the value (cannot be called for objects). */ +SPL_METHOD(Array, append) +{ + zval *value; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { + return; + } + spl_array_iterator_append(getThis(), value TSRMLS_CC); +} /* }}} */ + /* {{{ proto void ArrayObject::offsetUnset(mixed $index) proto void ArrayIterator::offsetUnset(mixed $index) Unsets the value at the specified $index. */ diff --git a/ext/spl/spl_array.h b/ext/spl/spl_array.h index 1e9b402dcb..cf29ae439e 100755 --- a/ext/spl/spl_array.h +++ b/ext/spl/spl_array.h @@ -29,6 +29,8 @@ extern zend_class_entry *spl_ce_ArrayIterator; PHP_MINIT_FUNCTION(spl_array); +extern void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC); + #endif /* SPL_ARRAY_H */ /* diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index ed81cf7af8..e270657cea 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -33,6 +33,7 @@ #include "spl_engine.h" #include "spl_iterators.h" #include "spl_directory.h" +#include "spl_array.h" #define INLINE inline @@ -49,6 +50,7 @@ zend_class_entry *spl_ce_IteratorIterator; zend_class_entry *spl_ce_NoRewindIterator; zend_class_entry *spl_ce_InfiniteIterator; zend_class_entry *spl_ce_EmptyIterator; +zend_class_entry *spl_ce_AppendIterator; function_entry spl_funcs_RecursiveIterator[] = { SPL_ABSTRACT_ME(RecursiveIterator, hasChildren, NULL) @@ -646,6 +648,12 @@ static INLINE spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAME } break; } + case DIT_AppendIterator: + spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 1 TSRMLS_CC); + zend_call_method_with_0_params(&intern->u.append.zarrayit, spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL); + intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, intern->u.append.zarrayit TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + return intern; default: if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobject, ce_inner) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); @@ -698,7 +706,6 @@ static INLINE void spl_dual_it_require(spl_dual_it_object *intern TSRMLS_DC) static INLINE void spl_dual_it_free(spl_dual_it_object *intern TSRMLS_DC) { - spl_dual_it_require(intern TSRMLS_CC); if (intern->inner.iterator && intern->inner.iterator->funcs->invalidate_current) { intern->inner.iterator->funcs->invalidate_current(intern->inner.iterator TSRMLS_CC); } @@ -801,6 +808,7 @@ SPL_METHOD(dual_it, valid) proto mixed ParentIterator::key() proto mixed IteratorIterator::key() proto mixed NoRewindIterator::key() + proto mixed AppendIterator::key() Get the current key */ SPL_METHOD(dual_it, key) { @@ -824,6 +832,7 @@ SPL_METHOD(dual_it, key) proto mixed ParentIterator::current() proto mixed IteratorIterator::current() proto mixed NoRewindIterator::current() + proto mixed AppendIterator::current() Get the current element value */ SPL_METHOD(dual_it, current) { @@ -951,6 +960,11 @@ static INLINE void spl_dual_it_free_storage(void *_object TSRMLS_DC) if (object->inner.zobject) { zval_ptr_dtor(&object->inner.zobject); } + + if (object->dit_type == DIT_AppendIterator) { + object->u.append.iterator->funcs->dtor(object->u.append.iterator TSRMLS_CC); + zval_ptr_dtor(&object->u.append.zarrayit); + } zend_hash_destroy(object->std.properties); FREE_HASHTABLE(object->std.properties); @@ -1415,15 +1429,65 @@ SPL_METHOD(NoRewindIterator, __construct) spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_ce_iterator, DIT_NoRewindIterator); } /* }}} */ -/* {{{ proto NoRewindIterator::rewind() - Prevent a call to inner iterators rewind() (internally the current data will be fetched if valid()) */ +/* {{{ proto void NoRewindIterator::rewind() + Prevent a call to inner iterators rewind() */ SPL_METHOD(NoRewindIterator, rewind) { + /* nothing to do */ +} /* }}} */ + +/* {{{ proto void NoRewindIterator::valid() + Return inner iterators valid() */ +SPL_METHOD(NoRewindIterator, valid) +{ + spl_dual_it_object *intern; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + RETURN_BOOL(intern->inner.iterator->funcs->valid(intern->inner.iterator TSRMLS_CC) == SUCCESS); +} /* }}} */ + +/* {{{ proto mixed NoRewindIterator::key() + Return inner iterators key() */ +SPL_METHOD(NoRewindIterator, key) +{ spl_dual_it_object *intern; intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_dual_it_fetch(intern, 1 TSRMLS_CC); + if (intern->inner.iterator->funcs->get_current_key) { + char *str_key; + uint str_key_len; + ulong int_key; + if (intern->inner.iterator->funcs->get_current_key(intern->inner.iterator, &str_key, &str_key_len, &int_key TSRMLS_CC) == HASH_KEY_IS_LONG) { + RETURN_LONG(int_key); + } else { + RETURN_STRINGL(str_key, str_key_len-1, 0); + } + } else { + RETURN_NULL(); + } +} /* }}} */ + +/* {{{ proto mixed NoRewindIterator::current() + Return inner iterators current() */ +SPL_METHOD(NoRewindIterator, current) +{ + spl_dual_it_object *intern; + zval **data; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC); + RETURN_ZVAL(*data, 1, 0); +} /* }}} */ + +/* {{{ proto void NoRewindIterator::next() + Return inner iterators next() */ +SPL_METHOD(NoRewindIterator, next) +{ + spl_dual_it_object *intern; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); } /* }}} */ static @@ -1434,10 +1498,10 @@ ZEND_END_ARG_INFO(); static zend_function_entry spl_funcs_NoRewindIterator[] = { SPL_ME(NoRewindIterator, __construct, arginfo_norewind_it___construct, ZEND_ACC_PUBLIC) SPL_ME(NoRewindIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, next, NULL, ZEND_ACC_PUBLIC) + SPL_ME(NoRewindIterator, valid, NULL, ZEND_ACC_PUBLIC) + SPL_ME(NoRewindIterator, key, NULL, ZEND_ACC_PUBLIC) + SPL_ME(NoRewindIterator, current, NULL, ZEND_ACC_PUBLIC) + SPL_ME(NoRewindIterator, next, NULL, ZEND_ACC_PUBLIC) SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -1514,6 +1578,136 @@ static zend_function_entry spl_funcs_EmptyIterator[] = { SPL_ME(EmptyIterator, next, NULL, ZEND_ACC_PUBLIC) }; +int spl_append_it_next_iterator(spl_dual_it_object *intern TSRMLS_DC) /* {{{*/ +{ + spl_dual_it_free(intern TSRMLS_CC); + + if (intern->inner.zobject) { + zval_ptr_dtor(&intern->inner.zobject); + intern->inner.zobject = NULL; + intern->inner.ce = NULL; + intern->inner.object = NULL; + intern->inner.iterator = NULL; + } + if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator TSRMLS_CC) == SUCCESS) { + zval **it; + + intern->u.append.iterator->funcs->get_current_data(intern->u.append.iterator, &it TSRMLS_CC); + (*it)->refcount++; + intern->inner.zobject = *it; + intern->inner.ce = Z_OBJCE_PP(it); + intern->inner.object = zend_object_store_get_object(*it TSRMLS_CC); + intern->inner.iterator = intern->inner.ce->get_iterator(intern->inner.ce, *it TSRMLS_CC); + spl_dual_it_rewind(intern TSRMLS_CC); + intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator TSRMLS_CC); + return SUCCESS; + } else { + return FAILURE; + } +} /* }}} */ + +void spl_append_it_fetch(spl_dual_it_object *intern TSRMLS_DC) /* {{{*/ +{ + while (spl_dual_it_valid(intern TSRMLS_CC) != SUCCESS) { + if (spl_append_it_next_iterator(intern TSRMLS_CC) != SUCCESS) { + return; + } + } + spl_dual_it_fetch(intern, 0 TSRMLS_CC); +} /* }}} */ + +void spl_append_it_next(spl_dual_it_object *intern TSRMLS_DC) /* {{{ */ +{ + if (spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) { + spl_dual_it_next(intern, 1 TSRMLS_CC); + } + spl_append_it_fetch(intern TSRMLS_CC); +} /* }}} */ + +/* {{{ proto AppendIterator::__construct() + Create an AppendIterator */ +SPL_METHOD(AppendIterator, __construct) +{ + spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_ce_iterator, DIT_AppendIterator); +} /* }}} */ + +/* {{{ proto void AppendIterator::append(Iterator it) + Append an iterator */ +SPL_METHOD(AppendIterator, append) +{ + spl_dual_it_object *intern; + zval *it; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &it, zend_ce_iterator) == FAILURE) { + return; + } + spl_array_iterator_append(intern->u.append.zarrayit, it TSRMLS_CC); + + if (!intern->inner.iterator || spl_dual_it_valid(intern TSRMLS_CC) != SUCCESS) { + if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator TSRMLS_CC) != SUCCESS) { + intern->u.append.iterator->funcs->rewind(intern->u.append.iterator TSRMLS_CC); + } + do { + spl_append_it_next_iterator(intern TSRMLS_CC); + } while (intern->inner.zobject != it); + spl_append_it_fetch(intern TSRMLS_CC); + } +} /* }}} */ + +/* {{{ proto void AppendIterator::rewind() + Rewind to the first iterator and rewind the first iterator, too */ +SPL_METHOD(AppendIterator, rewind) +{ + spl_dual_it_object *intern; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + intern->u.append.iterator->funcs->rewind(intern->u.append.iterator TSRMLS_CC); + if (spl_append_it_next_iterator(intern TSRMLS_CC) == SUCCESS) { + spl_append_it_fetch(intern TSRMLS_CC); + } +} /* }}} */ + +/* {{{ proto boolean AppendIterator::valid() + Check if the current state is valid */ +SPL_METHOD(AppendIterator, valid) +{ + spl_dual_it_object *intern; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + RETURN_BOOL(intern->current.data); +} /* }}} */ + +/* {{{ proto AppendIterator::next() + Forward to next element */ +SPL_METHOD(AppendIterator, next) +{ + spl_dual_it_object *intern; + + intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); + + spl_append_it_next(intern TSRMLS_CC); +} /* }}} */ + +static +ZEND_BEGIN_ARG_INFO(arginfo_append_it_append, 0) + ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) +ZEND_END_ARG_INFO(); + +static zend_function_entry spl_funcs_AppendIterator[] = { + SPL_ME(AppendIterator, __construct, NULL, ZEND_ACC_PUBLIC) + SPL_ME(AppendIterator, append, arginfo_append_it_append, ZEND_ACC_PUBLIC) + SPL_ME(AppendIterator, rewind, NULL, ZEND_ACC_PUBLIC) + SPL_ME(AppendIterator, valid, NULL, ZEND_ACC_PUBLIC) + SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) + SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) + SPL_ME(AppendIterator, next, NULL, ZEND_ACC_PUBLIC) + SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) +}; + /* {{{ array iterator_to_array(IteratorAggregate it) Copy the iterator into an array */ PHP_FUNCTION(iterator_to_array) @@ -1640,12 +1834,15 @@ PHP_MINIT_FUNCTION(spl_iterators) REGISTER_SPL_INTERFACE(OuterIterator); REGISTER_SPL_ITERATOR(OuterIterator); + REGISTER_SPL_STD_CLASS_EX(AppendIterator, spl_dual_it_new, spl_funcs_AppendIterator); + REGISTER_SPL_IMPLEMENTS(RecursiveIteratorIterator, OuterIterator); REGISTER_SPL_IMPLEMENTS(CachingIterator, OuterIterator); REGISTER_SPL_IMPLEMENTS(FilterIterator, OuterIterator); REGISTER_SPL_IMPLEMENTS(LimitIterator, OuterIterator); REGISTER_SPL_IMPLEMENTS(IteratorIterator, OuterIterator); REGISTER_SPL_IMPLEMENTS(NoRewindIterator, OuterIterator); + REGISTER_SPL_IMPLEMENTS(AppendIterator, OuterIterator); REGISTER_SPL_SUB_CLASS_EX(InfiniteIterator, IteratorIterator, spl_dual_it_new, spl_funcs_InfiniteIterator); diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h index 185bf54b59..c717c532b4 100755 --- a/ext/spl/spl_iterators.h +++ b/ext/spl/spl_iterators.h @@ -37,6 +37,7 @@ extern zend_class_entry *spl_ce_IteratorIterator; extern zend_class_entry *spl_ce_NoRewindIterator; extern zend_class_entry *spl_ce_InfiniteIterator; extern zend_class_entry *spl_ce_EmptyIterator; +extern zend_class_entry *spl_ce_AppendIterator; PHP_MINIT_FUNCTION(spl_iterators); @@ -51,6 +52,7 @@ typedef enum { DIT_IteratorIterator, DIT_NoRewindIterator, DIT_InfiniteIterator, + DIT_AppendIterator, } dual_it_type; enum { @@ -90,6 +92,10 @@ typedef struct _spl_dual_it_object { zval *zstr; zval *zchildren; } caching; + struct { + zval *zarrayit; + zend_object_iterator *iterator; + } append; } u; } spl_dual_it_object; diff --git a/ext/spl/tests/iterator_001.phpt b/ext/spl/tests/iterator_001.phpt index 2fd690294e..2239417778 100755 --- a/ext/spl/tests/iterator_001.phpt +++ b/ext/spl/tests/iterator_001.phpt @@ -47,7 +47,7 @@ class NumericArrayIterator implements Iterator $this->i++; } - public function greaterThen($comp) + public function greaterThan($comp) { echo get_class($this) . '::' . __FUNCTION__ . '(' . $comp . ")\n"; return $this->current() > $comp; @@ -69,7 +69,7 @@ $a = array(1, 2, 3, 4, 5); $it = new LimitIterator(new NumericArrayIterator($a), 1, 3); foreach ($it as $v) { - print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; + print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } echo "===SEEKABLE===\n"; @@ -77,15 +77,16 @@ $a = array(1, 2, 3, 4, 5); $it = new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3); foreach($it as $v) { - print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; + print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } echo "===STACKED===\n"; +echo "Shows '2 is greater than 2' because the test is actually done with the current value which is 3.\n"; $a = array(1, 2, 3, 4, 5); $it = new CachingIterator(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3)); foreach($it as $v) { - print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; + print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } ?> @@ -100,19 +101,22 @@ NumericArrayIterator::valid(true) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +NumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 2 is less than or equal 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +NumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 3 is greater than 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +NumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 4 is greater than 2 NumericArrayIterator::next ===SEEKABLE=== @@ -122,22 +126,26 @@ SeekableNumericArrayIterator::seek(1) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 2 is less than or equal 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 3 is greater than 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -LimitIterator::greaterThen(2) +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 4 is greater than 2 NumericArrayIterator::next ===STACKED=== +Shows '2 is greater than 2' because the test is actually done with the current value which is 3. NumericArrayIterator::__construct NumericArrayIterator::rewind SeekableNumericArrayIterator::seek(1) @@ -148,15 +156,18 @@ NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -CachingIterator::greaterThen(2) -2 is less than or equal 2 +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current +2 is greater than 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key -CachingIterator::greaterThen(2) +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 3 is greater than 2 NumericArrayIterator::next -CachingIterator::greaterThen(2) +SeekableNumericArrayIterator::greaterThan(2) +NumericArrayIterator::current 4 is greater than 2 ===DONE=== diff --git a/ext/spl/tests/iterator_007.phpt b/ext/spl/tests/iterator_007.phpt index e40e2a245a..eb87977ac9 100755 --- a/ext/spl/tests/iterator_007.phpt +++ b/ext/spl/tests/iterator_007.phpt @@ -121,54 +121,48 @@ ArrayIteratorEx::next ArrayIteratorEx::valid ===1=== NoRewindIteratorEx::rewind -ArrayIteratorEx::valid NoRewindIteratorEx::valid +ArrayIteratorEx::valid ===2=== NoRewindIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key NoRewindIteratorEx::valid +ArrayIteratorEx::valid NoRewindIteratorEx::current +ArrayIteratorEx::current int(0) NoRewindIteratorEx::next ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key NoRewindIteratorEx::valid +ArrayIteratorEx::valid NoRewindIteratorEx::current +ArrayIteratorEx::current int(1) NoRewindIteratorEx::next ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key NoRewindIteratorEx::valid +ArrayIteratorEx::valid NoRewindIteratorEx::current +ArrayIteratorEx::current int(2) ===3=== NoRewindIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key NoRewindIteratorEx::valid +ArrayIteratorEx::valid NoRewindIteratorEx::current int(2) NoRewindIteratorEx::next ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key NoRewindIteratorEx::valid +ArrayIteratorEx::valid NoRewindIteratorEx::current +ArrayIteratorEx::current int(3) NoRewindIteratorEx::next ArrayIteratorEx::next -ArrayIteratorEx::valid NoRewindIteratorEx::valid +ArrayIteratorEx::valid ===4=== NoRewindIteratorEx::rewind -ArrayIteratorEx::valid NoRewindIteratorEx::valid +ArrayIteratorEx::valid ===DONE=== diff --git a/ext/spl/tests/iterator_010.phpt b/ext/spl/tests/iterator_010.phpt new file mode 100755 index 0000000000..39d1000f62 --- /dev/null +++ b/ext/spl/tests/iterator_010.phpt @@ -0,0 +1,18 @@ +--TEST-- +SPL: EmptyIterator +--FILE-- +<?php + +echo "===EmptyIterator===\n"; + +foreach(new LimitIterator(new EmptyIterator(), 0, 3) as $key => $val) +{ + echo "$key=>$val\n"; +} + +?> +===DONE=== +<?php exit(0); +--EXPECTF-- +===EmptyIterator=== +===DONE=== diff --git a/ext/spl/tests/iterator_011.phpt b/ext/spl/tests/iterator_011.phpt new file mode 100755 index 0000000000..9c234bb11d --- /dev/null +++ b/ext/spl/tests/iterator_011.phpt @@ -0,0 +1,51 @@ +--TEST-- +SPL: InfiniteIterator +--FILE-- +<?php + +echo "===EmptyIterator===\n"; + +foreach(new LimitIterator(new InfiniteIterator(new EmptyIterator()), 0, 3) as $key=>$val) +{ + echo "$key=>$val\n"; +} + +echo "===InfiniteIterator===\n"; + +$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); +$it = new InfiniteIterator($it); +$it = new LimitIterator($it, 2, 5); +foreach($it as $val=>$key) +{ + echo "$val=>$key\n"; +} + +echo "===Infinite/LimitIterator===\n"; + +$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); +$it = new LimitIterator($it, 1, 2); +$it = new InfiniteIterator($it); +$it = new LimitIterator($it, 2, 5); +foreach($it as $val=>$key) +{ + echo "$val=>$key\n"; +} + +?> +===DONE=== +<?php exit(0); +--EXPECTF-- +===EmptyIterator=== +===InfiniteIterator=== +2=>C +3=>D +0=>A +1=>B +2=>C +===Infinite/LimitIterator=== +1=>B +2=>C +1=>B +2=>C +1=>B +===DONE=== diff --git a/ext/spl/tests/iterator_012.phpt b/ext/spl/tests/iterator_012.phpt new file mode 100755 index 0000000000..09842b0988 --- /dev/null +++ b/ext/spl/tests/iterator_012.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL: NoRweindIterator +--FILE-- +<?php + +echo "===Current===\n"; + +$it = new NoRewindIterator(new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C'))); + +echo $it->key() . '=>' . $it->current() . "\n"; + +echo "===Next===\n"; + +$it->next(); + +echo "===Foreach===\n"; + +foreach($it as $key=>$val) +{ + echo "$key=>$val\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===Current=== +0=>A +===Next=== +===Foreach=== +1=>B +2=>C +===DONE=== diff --git a/ext/spl/tests/iterator_013.phpt b/ext/spl/tests/iterator_013.phpt new file mode 100755 index 0000000000..119631c000 --- /dev/null +++ b/ext/spl/tests/iterator_013.phpt @@ -0,0 +1,66 @@ +--TEST-- +SPL: AppendIterator +--FILE-- +<?php + +echo "===Empty===\n"; + +$it = new AppendIterator; + +foreach($it as $key=>$val) +{ + echo "$key=>$val\n"; +} + +echo "===Append===\n"; + +$it->append(new ArrayIterator(array(0 => 'A', 1 => 'B'))); + +foreach($it as $key=>$val) +{ + echo "$key=>$val\n"; +} + +echo "===Rewind===\n"; + +foreach($it as $key=>$val) +{ + echo "$key=>$val\n"; +} + +echo "===Append===\n"; + +$it->append(new ArrayIterator(array(2 => 'C', 3 => 'D'))); + +foreach(new NoRewindIterator($it) as $key=>$val) +{ + echo "$key=>$val\n"; +} + +echo "===Rewind===\n"; + +foreach($it as $key=>$val) +{ + echo "$key=>$val\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +===Empty=== +===Append=== +0=>A +1=>B +===Rewind=== +0=>A +1=>B +===Append=== +2=>C +3=>D +===Rewind=== +0=>A +1=>B +2=>C +3=>D +===DONE=== |