X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fplflagset.php;h=b5f30d93cfc350fbb9ad59d4eccd5f43b044f9d2;hb=e3c131627aa03f7107709e6d44c7840c09847acd;hp=e18adcf5c19167cd4589341c9683645673a4cf1d;hpb=2ab75571bf840471fa9559292b75852bfce004d3;p=platal.git diff --git a/classes/plflagset.php b/classes/plflagset.php index e18adcf..b5f30d9 100644 --- a/classes/plflagset.php +++ b/classes/plflagset.php @@ -21,7 +21,7 @@ /** class for describing flags */ -class PlFlagSet +class PlFlagSet extends PlAbstractIterable implements XDBFormat { /** string that holds the PlFlagSet */ private $values = array(); @@ -39,7 +39,9 @@ class PlFlagSet $this->sep = $sep; $splitted = explode($sep, $flags); foreach ($splitted as $part) { - $this->values[$part] = true; + if (!empty($part)) { + $this->values[$part] = true; + } } } @@ -118,6 +120,28 @@ class PlFlagSet } return $flags; } + + + /** format for XDB + */ + public function format() + { + 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: