From 61714a530869296f2dbdb13eaa344d38d51dc7be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 1 Dec 2011 22:42:43 +0100 Subject: [PATCH] Use SPL-Interfaces in \wcf\system\breadcrumb\Breadcrumbs Countable and Iterator are implemented. --- com.woltlab.wcf/template/breadcrumbs.tpl | 6 +-- .../system/breadcrumb/Breadcrumbs.class.php | 49 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/template/breadcrumbs.tpl b/com.woltlab.wcf/template/breadcrumbs.tpl index b600c8a3ed..56913fe9c1 100644 --- a/com.woltlab.wcf/template/breadcrumbs.tpl +++ b/com.woltlab.wcf/template/breadcrumbs.tpl @@ -1,11 +1,11 @@ -{if $__wcf->getBreadcrumbs()->get()|count} +{if $__wcf->getBreadcrumbs()|count} -{/if} \ No newline at end of file +{/if} diff --git a/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php b/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php index 74b64e5b36..35a93eeb27 100644 --- a/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php +++ b/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php @@ -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 */ 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++; + } } -- 2.20.1