com php-src: Added recursivetreeiterator::setPostfix() method: NEWS UPGRADING ext/spl/spl_iterators.c ext/spl/tests/recursive
_tree_iterator_setpostfix.phpt
| From: | Stanislav Malyshev | Date: | Mon, 22 Jul 2013 05:20:58 +0000 |
| Subject: | com php-src: Added recursivetreeiterator::setPostfix() method: NEWS UPGRADING ext/spl/spl_iterators.c ext/spl/tests/recursive _tree_iterator_setpostfix.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-72722@lists.php.net to get a copy of this message | ||
Commit: 5027fa79d72d513a4cd76e92ee1c6d9192b66a9e
Author: Joshua Thijssen <jthijssen@noxlogic.nl> Mon, 21 May 2012 15:30:24 +0200
Committer: Stanislav Malyshev <stas@php.net> Sun, 21 Jul 2013 22:20:58 -0700
Parents: 2c23004a1e3eb14695e6c44e52e4d5fe2a2d37d9
Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5027fa79d72d513a4cd76e92ee1c6d9192b66a9e
Log:
Added recursivetreeiterator::setPostfix() method
Changed paths:
M NEWS
M UPGRADING
M ext/spl/spl_iterators.c
A ext/spl/tests/recursive_tree_iterator_setpostfix.phpt
Diff:
diff --git a/NEWS b/NEWS
index 6a24e7a..b9d3446 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 7442067..741bcd9 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 25b8b4c..3053275 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 0000000..d59e278
--- /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===