Use SPL-Interfaces in \wcf\system\breadcrumb\Breadcrumbs
authorTim Düsterhus <timwolla@arcor.de>
Thu, 1 Dec 2011 21:42:43 +0000 (22:42 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Thu, 1 Dec 2011 21:42:43 +0000 (22:42 +0100)
Countable and Iterator are implemented.

com.woltlab.wcf/template/breadcrumbs.tpl
wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php

index b600c8a3eda6c17ef0432c666865354faa0bf28d..56913fe9c19fd02a240daab7c62c4cfeab936526 100644 (file)
@@ -1,11 +1,11 @@
-{if $__wcf->getBreadcrumbs()->get()|count}
+{if $__wcf->getBreadcrumbs()|count}
 <nav class="breadcrumbs">
        <ul>
-               {foreach from=$__wcf->getBreadcrumbs()->get() item=$breadcrumb}
+               {foreach from=$__wcf->getBreadcrumbs() item=$breadcrumb}
                        <li title="{$breadcrumb->getLabel()}" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
                                {if $breadcrumb->getURL()}<a href="{$breadcrumb->getURL()}" itemprop="url">{/if}<span itemprop="title">{$breadcrumb->getLabel()}</span>{if $breadcrumb->getURL()}</a>{/if} <span><span>&raquo;</span></span>
                        </li>
                {/foreach}
        </ul>
 </nav>
-{/if}
\ No newline at end of file
+{/if}
index 74b64e5b36f82321f36b908b5dca49f35850fd3e..35a93eeb2740f4a69a302e8087b6932a8a3f38c9 100644 (file)
@@ -12,13 +12,18 @@ use wcf\system\SingletonFactory;
  * @subpackage system.breadcrumb
  * @category   Community Framework
  */
-class Breadcrumbs extends SingletonFactory {
+class Breadcrumbs extends SingletonFactory implements \Countable, \Iterator {
        /**
         * list of breadcrumbs
         * @var array<wcf\system\breadcrumb\Breadcrumb>
         */     
        protected $items = array();
        
+       /**
+        * Current iterator-index
+        */
+       protected $index = 0;
+       
        /**
         * Adds a breadcrumb (insertion order is crucial!).
         * 
@@ -69,4 +74,46 @@ class Breadcrumbs extends SingletonFactory {
                
                return false;
        }
+       
+       /**
+        * @see \Countable::count()
+        */
+       public function count() {
+               return count($this->items);
+       }
+       
+       /**
+        * @see \Iterator::current()
+        */
+       public function current() {
+               return $this->items[$this->index];
+       }
+       
+       /**
+        * @see \Iterator::key()
+        */
+       public function key() {
+               return $this->index;
+       }
+       
+       /**
+        * @see \Iterator::valid()
+        */
+       public function valid() {
+               return isset($this->items[$this->index]);
+       }
+       
+       /**
+        * @see \Iterator::rewind()
+        */
+       public function rewind() {
+               $this->index = 0;
+       }
+       
+       /**
+        * @see \Iterator::next()
+        */
+       public function next() {
+               $this->index++;
+       }
 }