X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fflagset.php;h=ce3d55851fc776eddec41e940249e14463abc8fa;hb=efd0a58a80002640e51bd4bc3c7ef1e71a3cc64c;hp=9a86ad6f5758a2491d5e649e89fb3003b5898ace;hpb=42a50827dc2ac2b13ddaf77ea16c0989cd8b960d;p=platal.git diff --git a/classes/flagset.php b/classes/flagset.php index 9a86ad6..ce3d558 100644 --- a/classes/flagset.php +++ b/classes/flagset.php @@ -21,70 +21,102 @@ /** class for describing flags */ -class flagset { - /** string that holds the flagset */ - var $value; +class Flagset +{ + /** string that holds the flagset */ + private $value; - /** the boundary between flags */ - var $sep = ","; + /** the boundary between flags */ + private $sep = ","; - /** set flag - * @param $flags services FROM coupures - * @return VOID - */ - function flagset( $flags="" ) { - $this->value = $flags; - } + /** set flag + * @param $flags services FROM coupures + * @return VOID + */ + public function __construct($flags = "") + { + $this->value = $flags; + } - /** add flag - * @param $flag XXX - * @return VOID - */ - function addflag($flag) { - if (!$flag) return; - if (!$this->hasflag($flag)) { - if ($this->value) - $this->value .= $this->sep; - $this->value .= $flag; + /** add flag + * @param $flag XXX + * @return VOID + */ + public function addFlag($flag) + { + if (!$flag) return; + if (!$this->hasflag($flag)) { + if ($this->value) + $this->value .= $this->sep; + $this->value .= $flag; + } } - } - /** test si flag ou pas - * @param $flag XXX - * @return 1 || 0 - */ - function hasflag($flag) { - $tok = strtok($this->value,$this->sep); - while ($tok) { - if ($tok==$flag) return 1; - $tok = strtok($this->sep); + /** test si flag ou pas + * @param $flag XXX + * @return 1 || 0 + */ + public function hasFlag($flag) + { + $tok = strtok($this->value,$this->sep); + while ($tok) { + if ($tok==$flag) return 1; + $tok = strtok($this->sep); + } + return 0; } - return 0; - } + /** 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 - */ - function rmflag($flag) { - if (!$flag) return; - $newvalue = ""; - $tok = strtok($this->value,$this->sep); - while ($tok) { - if ($tok!=$flag) { - if ($newvalue) - $newvalue .= $this->sep; - $newvalue .= $tok; - } - $tok = strtok($this->sep); + /** remove flag + * @param $flag XXX + * @return VOID + */ + public function rmFlag($flag) + { + if (!$flag) return; + $newvalue = ""; + $tok = strtok($this->value,$this->sep); + while ($tok) { + if ($tok!=$flag) { + if ($newvalue) + $newvalue .= $this->sep; + $newvalue .= $tok; + } + $tok = strtok($this->sep); + } + $this->value=$newvalue; } - $this->value=$newvalue; - } -} + /** return the flagset + */ + public function flags() + { + return $this->value; + } +} +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>