sep = $sep; $splitted = explode($sep, $flags); foreach ($splitted as $part) { if (!empty($part)) { $this->values[$part] = true; } } } /** add flag * @param $flag name of the flag * @param $cond if true, add the flag (default is true), else, ignore. * @return VOID */ public function addFlag($flag, $cond = true) { if (empty($flag) || !$cond) { return; } $this->values[$flag] = true; } /** test si flag ou pas * @param $flag XXX * @return 1 || 0 */ public function hasFlag($flag) { return !empty($flag) && isset($this->values[$flag]) && $this->values[$flag]; } /** test flag combination */ public function hasFlagCombination($flag) { $perms = explode(',', $flag); foreach ($perms as $perm) { $ok = true; $rights = explode(':', $perm); foreach ($rights as $right) { if (($right{0} == '!' && $this->hasFlag(substr($right, 1))) || !$this->hasFlag($right)) { $ok = false; } } if ($ok) { return true; } } return false; } /** remove flag * @param $flag XXX * @return VOID */ public function rmFlag($flag) { if (empty($flag)) { return; } if (isset($this->values[$flag])) { unset($this->values[$flag]); } } /** Remove all the flags. */ public function clear() { $this->values = array(); } /** return the PlFlagSet */ public function flags() { $flags = ''; foreach ($this->values as $key=>$value) { if (!empty($flags)) { $flags .= $this->sep; } if ($value) { $flags .= $key; } } return $flags; } /** export the PlFlagSet */ public function export() { $array = array(); foreach ($this->values as $key=>$value) { if ($value) { $array[] = $key; } } return $array; } /** format for XDB */ public function format() { return XDB::escape($this->flags()); } /** Build an iterator for this PlFlagSet. */ public function iterate() { return PlIteratorUtils::fromArray($this->export(), 1, true); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>