From f8566cee3aa4374ca56093f4068fe5b25e2f6994 Mon Sep 17 00:00:00 2001 From: Mridang Agarwalla Date: Tue, 9 May 2017 10:11:03 +0300 Subject: [PATCH] Modified the abstract collection to be countable. --- src/Object/AbstractCollection.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Object/AbstractCollection.php b/src/Object/AbstractCollection.php index c55e688c..0592bdfd 100644 --- a/src/Object/AbstractCollection.php +++ b/src/Object/AbstractCollection.php @@ -36,6 +36,7 @@ namespace Nosto\Object; +use Countable; use Iterator; /** @@ -43,7 +44,7 @@ * functionality to validate the items added to the collection. The collection behaves * like an array. making it easy to add items to it and iterate over it. */ -abstract class AbstractCollection implements Iterator +abstract class AbstractCollection implements Iterator, Countable { protected $var = array(); @@ -80,6 +81,14 @@ public function next() return next($this->var); } + /** + * @see Iterator::next() + */ + public function count() + { + return count($this->var); + } + /** * @see Iterator::valid() */