summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Thijssen <jthijssen@noxlogic.nl>2012-05-21 15:30:24 +0200
committerStanislav Malyshev <stas@php.net>2013-07-21 22:20:58 -0700
commit5027fa79d72d513a4cd76e92ee1c6d9192b66a9e (patch)
treea1c5d25c6bbdf4e264377b804c2a5888da4ba30f
parent2c23004a1e3eb14695e6c44e52e4d5fe2a2d37d9 (diff)
downloadphp-git-5027fa79d72d513a4cd76e92ee1c6d9192b66a9e.tar.gz
Added recursivetreeiterator::setPostfix() method
-rw-r--r--NEWS4
-rwxr-xr-xUPGRADING2
-rw-r--r--ext/spl/spl_iterators.c24
-rw-r--r--ext/spl/tests/recursive_tree_iterator_setpostfix.phpt88
4 files changed, 117 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 6a24e7a340..b9d3446c73 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ PHP NEWS
. Fixed bug #65291 (get_defined_constants() causes PHP to crash in a very
limited case). (Arpad)
+- SPL:
+ . Added RecursiveTreeIterator setPostfix and getPostifx methods. (Joshua
+ Thijssen)
+
- Streams:
. Fixed bug #65268 (select() implementation uses outdated tick API). (Anatol)
diff --git a/UPGRADING b/UPGRADING
index 744206787f..741bcd9683 100755
--- a/UPGRADING
+++ b/UPGRADING
@@ -297,6 +297,8 @@ PHP 5.5 UPGRADE NOTES
- SPL:
- SplFixedArray::__wakeup()
- SplDoublyLinkedList::add()
+ - RecursiveTreeIterator::getPostfix() (5.5.2)
+ - RecursiveTreeIterator::setPostfix() (5.5.2)
- Zend OPcache:
- opcache_get_configuration()
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 25b8b4c126..30532756cb 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -117,6 +117,7 @@ typedef struct _spl_recursive_it_object {
zend_function *nextElement;
zend_class_entry *ce;
smart_str prefix[6];
+ smart_str postfix[1];
} spl_recursive_it_object;
typedef struct _spl_recursive_it_iterator {
@@ -886,6 +887,8 @@ static void spl_RecursiveIteratorIterator_free_storage(void *_object TSRMLS_DC)
smart_str_free(&object->prefix[4]);
smart_str_free(&object->prefix[5]);
+ smart_str_free(&object->postfix[0]);
+
efree(object);
}
/* }}} */
@@ -906,6 +909,8 @@ static zend_object_value spl_RecursiveIteratorIterator_new_ex(zend_class_entry *
smart_str_appendl(&intern->prefix[3], "|-", 2);
smart_str_appendl(&intern->prefix[4], "\\-", 2);
smart_str_appendl(&intern->prefix[5], "", 0);
+
+ smart_str_appendl(&intern->postfix[0], "", 0);
}
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
@@ -1025,7 +1030,7 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object * obje
static void spl_recursive_tree_iterator_get_postfix(spl_recursive_it_object * object, zval * return_value TSRMLS_DC)
{
- RETVAL_STRINGL("", 0, 1);
+ RETVAL_STRINGL(object->postfix[0].c, object->postfix[0].len, 1);
}
/* {{{ proto void RecursiveTreeIterator::__construct(RecursiveIterator|IteratorAggregate it [, int flags = RTIT_BYPASS_KEY [, int cit_flags = CIT_CATCH_GET_CHILD [, mode = RIT_SELF_FIRST ]]]) throws InvalidArgumentException
@@ -1068,6 +1073,22 @@ SPL_METHOD(RecursiveTreeIterator, getPrefix)
spl_recursive_tree_iterator_get_prefix(object, return_value TSRMLS_CC);
} /* }}} */
+/* {{{ proto void RecursiveTreeIterator::setPostfix(string prefix)
+ Sets postfix as used in getPostfix() */
+SPL_METHOD(RecursiveTreeIterator, setPostfix)
+{
+ spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ char* postfix;
+ int postfix_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &postfix, &postfix_len) == FAILURE) {
+ return;
+ }
+
+ smart_str_free(&object->postfix[0]);
+ smart_str_appendl(&object->postfix[0], postfix, postfix_len);
+} /* }}} */
+
/* {{{ proto string RecursiveTreeIterator::getEntry()
Returns the string presentation built for current element */
SPL_METHOD(RecursiveTreeIterator, getEntry)
@@ -1235,6 +1256,7 @@ static const zend_function_entry spl_funcs_RecursiveTreeIterator[] = {
SPL_ME(RecursiveTreeIterator, getPrefix, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveTreeIterator, setPrefixPart, arginfo_recursive_tree_it_setPrefixPart, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveTreeIterator, getEntry, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
+ SPL_ME(RecursiveTreeIterator, setPostfix, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveTreeIterator, getPostfix, arginfo_recursive_it_void, ZEND_ACC_PUBLIC)
PHP_FE_END
};
diff --git a/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt b/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt
new file mode 100644
index 0000000000..d59e278fd6
--- /dev/null
+++ b/ext/spl/tests/recursive_tree_iterator_setpostfix.phpt
@@ -0,0 +1,88 @@
+--TEST--
+SPL: RecursiveTreeIterator::setPostfix()
+--CREDITS--
+Joshua Thijssen (jthijssen@noxlogic.nl)
+--FILE--
+<?php
+
+$arr = array(
+ 0 => array(
+ "a",
+ 1,
+ ),
+ "a" => array(
+ 2,
+ "b",
+ 3 => array(
+ 4,
+ "c",
+ ),
+ "3" => array(
+ 4,
+ "c",
+ ),
+ ),
+);
+
+$it = new RecursiveArrayIterator($arr);
+$it = new RecursiveTreeIterator($it);
+
+echo "----\n";
+echo $it->getPostfix();
+echo "\n\n";
+
+echo "----\n";
+$it->setPostfix("POSTFIX");
+echo $it->getPostfix();
+echo "\n\n";
+
+echo "----\n";
+foreach($it as $k => $v) {
+ echo "[$k] => $v\n";
+}
+
+echo "----\n";
+$it->setPostfix("");
+echo $it->getPostfix();
+echo "\n\n";
+
+echo "----\n";
+foreach($it as $k => $v) {
+ echo "[$k] => $v\n";
+}
+
+
+
+?>
+===DONE===
+--EXPECTF--
+----
+
+
+----
+POSTFIX
+
+----
+[0] => |-ArrayPOSTFIX
+[0] => | |-aPOSTFIX
+[1] => | \-1POSTFIX
+[a] => \-ArrayPOSTFIX
+[0] => |-2POSTFIX
+[1] => |-bPOSTFIX
+[3] => \-ArrayPOSTFIX
+[0] => |-4POSTFIX
+[1] => \-cPOSTFIX
+----
+
+
+----
+[0] => |-Array
+[0] => | |-a
+[1] => | \-1
+[a] => \-Array
+[0] => |-2
+[1] => |-b
+[3] => \-Array
+[0] => |-4
+[1] => \-c
+===DONE===