Skip to content

Commit

Permalink
- Minor fixes
Browse files Browse the repository at this point in the history
- Implement AppendIterator in C
  • Loading branch information
helly25 committed Nov 1, 2004
1 parent 9626e98 commit b947060
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 57 deletions.
4 changes: 0 additions & 4 deletions ext/spl/examples/tests/examples.inc
Expand Up @@ -13,10 +13,6 @@ class IncludeFiles extends ArrayIterator
}

$classes = array(
'EmptyIterator',
'InfiniteIterator',
'AppendIterator',
'NoRewindIterator',
);

foreach (new IncludeFiles(dirname(__FILE__). '/..', $classes) as $file)
Expand Down
@@ -1,15 +1,15 @@
<?php

/** @file appenditerator.inc
* @ingroup Examples
* @ingroup SPL
* @brief class AppendIterator
* @author Marcus Boerger
* @date 2003 - 2004
*
* 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
Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions ext/spl/php_spl.c
Expand Up @@ -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); \
Expand Down
27 changes: 16 additions & 11 deletions ext/spl/spl_array.c
Expand Up @@ -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;
Expand All @@ -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. */
Expand Down
2 changes: 2 additions & 0 deletions ext/spl/spl_array.h
Expand Up @@ -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 */

/*
Expand Down

0 comments on commit b947060

Please sign in to comment.