]> granicus.if.org Git - php/commitdiff
Added recursivetreeiterator::setPostfix() method
authorJoshua Thijssen <jthijssen@noxlogic.nl>
Mon, 21 May 2012 13:30:24 +0000 (15:30 +0200)
committerStanislav Malyshev <stas@php.net>
Mon, 22 Jul 2013 05:20:58 +0000 (22:20 -0700)
NEWS
UPGRADING
ext/spl/spl_iterators.c
ext/spl/tests/recursive_tree_iterator_setpostfix.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 6a24e7a340697bf925d80326cbb3ec1b24b2e688..b9d3446c7383589cfee841cfe7754d82a7bf3406 100644 (file)
--- 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)
 
index 744206787f99a982733556672ed961329f67b7aa..741bcd9683e22598e11432baceec05558800230c 100755 (executable)
--- 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()
index 25b8b4c126eeb93b55d81dda2debe86dd6e58072..30532756cb6d614bba6d079004eb7683ed3cddb2 100644 (file)
@@ -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 (file)
index 0000000..d59e278
--- /dev/null
@@ -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===