From 988a0ceddebb96949ca74e62129d9b3dbe2450c3 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Tue, 28 Sep 2010 11:16:08 +0200 Subject: [PATCH] PlFlagSet is iterable. Signed-off-by: Florent Bruneau --- classes/plflagset.php | 16 +++++++++++++++- ut/plflagsettest.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ut/plflagsettest.php diff --git a/classes/plflagset.php b/classes/plflagset.php index 28c7add..b5f30d9 100644 --- a/classes/plflagset.php +++ b/classes/plflagset.php @@ -21,7 +21,7 @@ /** class for describing flags */ -class PlFlagSet implements XDBFormat +class PlFlagSet extends PlAbstractIterable implements XDBFormat { /** string that holds the PlFlagSet */ private $values = array(); @@ -128,6 +128,20 @@ class PlFlagSet implements XDBFormat { return XDB::escape($this->flags()); } + + + /** Build an iterator for this PlFlagSet. + */ + public function iterate() + { + $array = array(); + foreach ($this->values as $key=>$value) { + if ($value) { + $array[] = $key; + } + } + return PlIteratorUtils::fromArray($array, 1, true); + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/ut/plflagsettest.php b/ut/plflagsettest.php new file mode 100644 index 0000000..065ad61 --- /dev/null +++ b/ut/plflagsettest.php @@ -0,0 +1,38 @@ +assertSame(array('a', 'b', 'c', 'd'), $array); + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> -- 2.1.4